Page 1 of 1

User Preference in Macro

Posted: Wed Aug 18, 2021 6:58 am
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.

Re: User Preference in Macro

Posted: Wed Aug 18, 2021 12:14 pm
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.

Re: User Preference in Macro

Posted: Fri Aug 20, 2021 2:16 am
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

Re: User Preference in Macro

Posted: Fri Aug 20, 2021 7:37 am
by JSculley
If you stop using VBA and switch to C#, you have the infrastructure for application and user settings built in: