I'm being asked to fix an Excel workbook where macros aren't working properly. The workbook includes an Auto-Open macro that changes content, including hiding or removing worksheets, and once it has run through, a second run always crashes because it's trying to select a worksheet previously deleted.
I want to step through Auto-Open but here's the catch:
If I open the workbook and choose to disable macros the macros is not viewable.
If I open the workbook and choose NOT to disable macros Auto-Open runs before I can stop it.
How can I step through Auto-Open on its first run?
Full answer trail is in the comments.
Macros are available for editing or debugging when disabled, but you need to use the right-click context menu in the expanded tree view of Microsoft Excel Objects to load the code into the edit panel (a single click shows an empty panel).
I put a "Stop" as the first command in the Auto-Open macro and saved the workbook. On re-opening the workbook I can choose to enable macros and let Auto-Open run, and jump straight into the debugger to step through on a first run.
Look at Debug.Assert False
You can just insert this as your first line in the auto-open subroutine
Debug.Assert Condition will stop the code and prompt debug if Condition = False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With