Saving workbook "hides" macros

dotsent

Board Regular
Joined
Feb 28, 2016
Messages
85
Office Version
  1. 365
Platform
  1. Windows
Hello all!

I have run automated VBA scripts for some years without much issues. Currently in Windows 10 and Office 365.
Windows task scheduler -> PowerShell script -> Excel + VBA code

There are various macros and workbooks, but most launch some PowerQuery connection, process data and might send out emails. For archiving and tracing reasons, macros usually end with ThisWorkbook.Save statement before closing.

For the past 3 months or so I have started to experience an annoying issue that saving the workbook causes macros to be "hidden" in the workbook. This in turn causes the situation where VBA code can't be launched the next time (targeted macro not found). Also, if I open the workbook manually and check "View" -> "Macros" I get this:

1708976775396.png


So, I can't even run them manually. The macros are somehow deleted, right?

Not quite. If I enter VBA editor (Alt + F11) I see all the expected code and modules - nothing is technically gone, just somehow not accessible after saving.

If I add a new module in VBA editor and copy all the existing VBA code there and then save the workbook, macros are "visible" again and possible to launch either manually or via automated script. I haven't seen a pattern of when it happens and to what kind of workbook it happens. While the macros are launched daily, this happens something like once a week. Also, this always happens when Excel macros are processed with an automated script - I have never experienced this when saving a workbook manually. With that being said, I don't really have a reason to save those workbooks often manually, so the sample size is low.

While I can "fix" the situation manually the main problem is that it breaks the automated flow which should really work consistently and independently. Any similar experiences or what could be the culprit? Or might there be a way to automatically fix that kind of workbook?

On the side - in some cases I have been able to do a workaround with ThisWorkbook.SaveCopyAs, but in some situations I can't avoid ThisWorkbook.Save, leaving my automated flow vulnerable. I have recently turned from VB Script to PowerShell, but the issues started already with VB Script. The same also happens in 2 different computers (similar setup though).
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi

Bugs,
Restore the entire sheet

Extract the code then save to xlsx
Finally add the code to save to xlsm
 
Upvote 0
Thanks for answering, I will try xlsm->xlsx->xlsm saving

But where are the bugs in? My VBA code? When it runs, there are no issues. It's not that complex either, but of course it's possible.
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,123,009
Members
449,093
Latest member
ikke

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