User Preference in Macro

Programming and macros
User avatar
zwei
Posts: 701
Joined: Mon Mar 15, 2021 9:17 pm
Answers: 18
Location: Malaysia
x 185
x 600

User Preference in Macro

Unread post by zwei »

Would like to get some opinions on whether is there a better way to do this...

Currently i have a few macros in my personal macro library which allow the user to "customize" the macro.

For example, I have a Copy Surface macro, and user can customize the colour of the copy surface feature without messing with the swp file.
The user will run a separate macro, MacroOption macro to adjust their preference. The setting will then be saved into a txt file,
When running the Copy Surface macro, the macro will then read the txt file, find the value and apply the colour according to the user preference
image.png
image.png

So far, the macros is working great, but I was just wondering whether will is there a better/easier way to handle these kinds of "User Preference" in solidworks macro without messing with the registry?

As i by no mean is a real programmer (most of my vba is taught by google search :P), I would like to get some opinions from the experts XD.
Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
User avatar
josh
Posts: 295
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 16
x 22
x 508

Re: User Preference in Macro

Unread post by josh »

IMHO the best way is to go ahead and use the registry. There is a free module available here: http://www.cpearson.com/Excel/Registry.htm that contains simple calls for all the registry stuff you need for saving and editing macro settings etc.

Additionally... You mentioned having a "separate macro" for editing settings. If you mean a separate .SWP file, I'd recommend just making it a separate sub within the same .swp file just so it doesn't get lost. When you map a macro button you can choose which sub to run in the same .swp file.
User avatar
zwei
Posts: 701
Joined: Mon Mar 15, 2021 9:17 pm
Answers: 18
Location: Malaysia
x 185
x 600

Re: User Preference in Macro

Unread post by zwei »

josh wrote: Wed Aug 18, 2021 12:14 pm IMHO the best way is to go ahead and use the registry. There is a free module available here: http://www.cpearson.com/Excel/Registry.htm that contains simple calls for all the registry stuff you need for saving and editing macro settings etc.
Thanks will take a look on the registry method.
Additionally... You mentioned having a "separate macro" for editing settings. If you mean a separate .SWP file, I'd recommend just making it a separate sub within the same .swp file just so it doesn't get lost. When you map a macro button you can choose which sub to run in the same .swp file.

I am keeping it as a separate macro instead of making it as a separate sub as it is used to control the option of multiple different macro.
For eg:
→ Macro1.swp
→ Macro2.swp
→ Macro3.swp
→ MacroOption4.swp is then used to control the option/preference for Macro 1, 2, and 3
Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
User avatar
JSculley
Posts: 646
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 879

Re: User Preference in Macro

Unread post by JSculley »

If you stop using VBA and switch to C#, you have the infrastructure for application and user settings built in:
Post Reply