Shawn V. Wilson
Shawn V. Wilson

Reputation: 1111

VBA - Save document without duplicating VBA code

I have a spreadsheet workbook that I'm using as a template.

The macro uses "SaveAs" to make a fresh copy of the workbook; this includes the macros themselves. At that point the template version is closed, and I'm working with a fresh version of the macro too.

I don't mind having duplicates of the macros, but any changes I make should be in the template version.

I tried saving the workbook as a non-macro-enabled version, thinking that there would only be the original macro module, but the new version still has the macros! They just "go away" when the workbook is saved. (Which means I could lose any changes I accidentally made there).

So I have these questions:

Upvotes: 2

Views: 178

Answers (1)

Dick Kusleika
Dick Kusleika

Reputation: 33145

This isn't going to be one of those satisfying answers, but the right answer is that your code should be separate from your template. Your code should live in an add-in and your template should be an .xlsx file. That way you always have one version of the code.

Upvotes: 1

Related Questions