Solidworks VBA macro not saving?

This is some weird behavoir of SolidWorks that I have come to understand and accept over time. It might not even be SolidWorks’s fault, but that’s where I have encountered it and where it has bugged me so many times.

You may notice this non-saving behavior when you are working on a macro in Visual Basic for Applications, or VBA for short. You will click on save and you assume the macro has been stored for all eternity. Then you close the editor and you get the following pop-up:

Save your already saved changes?
Save your already saved changes?

That unexpected warning explained

There are (at least) two possible reasons that you get this warning after you were so sure you hit the save button already:

  1. The file is read only
  2. Someone else has the macro in use as well

The third would be that you didn’t actually hit save, but I won’t mention that one. Oh wait, I just did. Damnit.

These two options are basically the same thing. When the file is read-only, you can’t get saving rights. This means you are only allowed to view and edit the file, but not save those edits. When someone before you opens the macro (running it via a shortcut or by opening it in the editor) on a shared network drive, Windows requests saving rights for that particular file. Which in turn means that you won’t be able to save.

How to actually save your changes

The bad thing is, you won’t get a warning until it is too late and you only get one opportunity to get it right. If you click “Yes” on the question “Save changes?” then it will try to save again. If that doesn’t work, which it never does because you don’t have saving rights, the VBA editor will just close without saving. If you click “No”, he VBA editor will close without saving as well. Only clicking the option “Cancel” can rescue your beloved edits.

You will return to your macro in the VBA editor after clicking Cancel. I would by now really appreciate a “Save As” button, but no such button exists. If you really want to save your changes, your only option is to copy all text into a new macro (return to SolidWorks, create a new macro) or into a text file. I know that these options are more workarounds than actual solutions, but these are the only options that I know of.

How to properly close a macro file

When multiple users make use of macro files on a network drive, the early bird gets the worm. That person will obtain saving rights, and keeps them until he closes SolidWorks. Find that early bird and get them to open the macro file in the VBA editor and close the file using File > Close and Return to SolidWorks. Closing the window in the upper right corner will not work! This will only close the editor, not the file.

What I usually do is wait until the end of the day to edit my macros. That’s because closing SolidWorks will also close all open macro files.

Being the last one on the floor has a few more advantages: the quiet office will aid you in your quest to build the ultimate time-saver, and nobody can hear you blame the computer for the bugs in your program!