Running a Macro on workbook open...

Skydyno

New Member
Joined
Aug 22, 2014
Messages
9
Hi all...

I'm wanting to run a macro (Menu_Hide) that activates some worksheet protection on when the workbook is first opened. (The macro below is in ThisWorkbook )

Private Sub Workbook_open()

Menu_Hide

End Sub


Menu_Hide is run from elsewhere when required (There is also a Menu_Show button). Menu_Hide runs perfectly well each time when manually activated by it's own button. :biggrin:

Now, what I don't understand is that when the workbook is opened the first time the Private Sub Workbook_open() runs, but Menu_Hide doesn't appear to have run (or taken affect). If I close the workbook and re-open it it does appear to have run. If I close & open a third time it doesn't, a 4th time it does.... and so on. ?:unsure:

Does anyone have an explanation and resolution for this behaviour? How can I get it to run the Menu_Hide macro reliably each time the workbook is opened?

Thanks in advance for your time and help with this, much appreciated. :cool:
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Do you have something in your Menu_Hide routine that might be interfering ?

Try introducing a small delay in the Workbook_Open before running the Menu_Hide macro (ie : Application.Ontime Now,"Menu_Hide") or use the workbook Activate Event and see if that fixes the problem.
 
Upvote 0
Do you have something in your Menu_Hide routine that might be interfering ?

Try introducing a small delay in the Workbook_Open before running the Menu_Hide macro (ie : Application.Ontime Now,"Menu_Hide") or use the workbook Activate Event and see if that fixes the problem.
Menu_Hide works fine every time when run manually from the button. It's only when it runs on startup that it misbehaves. It alternates from "works OK" to "Doesn't Work" on each open....

I'll look at a delay and see what happens, thanks :)
 
Upvote 0
Menu_Hide works fine every time when run manually from the button. It's only when it runs on startup that it misbehaves. It alternates from "works OK" to "Doesn't Work" on each open....

I'll look at a delay and see what happens, thanks :)
Gave it a go... No different... Toggles each time workbook is opened.
 
Upvote 0

Forum statistics

Threads
1,215,530
Messages
6,125,350
Members
449,220
Latest member
Edwin_SVRZ

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