Curious thing about saving an Excel file with macros.

Say you are working on an Excel spreadsheet, and you decided that you need a macro.

Instead of going through the classic path (Ribbon > Developer > Macro), you are an advanced user. So, you press Alt+F11 to open the Visual Studio for Applications.

In the Visual Basic environment, you choose to instead of creating a new module, you decide that you already have a pretty decent module right there: the ThisWorkbook module. No need to create anything.

Being a good developer, you decide that before writing any code, you'll explain, in comments, what the code is going to do and other things.

You're diligent and save your work from time to time.

Then, something happens, you need to close the worksheet you've been working on.

Nothing to fear, you saved all your work.

Then after you go back to that macro you're yet to create...

SURPRISE!

All that comment you made, explaining what was going to happen is no longer there.

Buh-bye!

Gone as if it was never there.

What the heck happened?

Well, in order to be considered a module, in VBA, a code file MUST have at least ONE routine (sub or function doesn't matter).

Only after that it will be considered a module. Only after that will Excel save it as a Visual Basic Project.

Comments