VBA code deleted in macro enabled workbook when i overwrite workbook with save as

9davros8

New Member
Joined
Jul 11, 2017
Messages
23
Hi guys


I have not used VBA for a long time so bear with me.

I have a VBA code that works in a macro enabled workbook – so the VBA code is specific to that book. However, every 2 months I need to overwrite this specific workbook and in the process the VBA code is deleted. I found out through trial and error that the code needs to be in this macro enabled workbook for it to work because it is triggered by a double click event. The workbook is the always the same name.


So, the question is how do I stop the code being deleted when I overwrite the specific workbook it is associated with?

And help appreciated

Thanks
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
What are you overwriting it with? If it's a different workbook that doesn't have the code in it, that is your problem.
 
Upvote 0
hi

basically i am creating a workbook called A.xlsx and on this workbook i run a macro the end result is that it saves this workbook as A.xlsm. However A.xlsm already exists so i have to overwrite it. the VBA code in this sheet is then deleted. From reading online the VBA code (it's a double click event) must be 'stored' in this workbook. I've tried storing the code in my personal workbook but am unable to 'call' it from there. any suggestions would be appreciated as the code does work.

thanks
 
Upvote 0
Why do you have to create a new workbook rather than just amending the existing one?
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top