Workbook_Open event fails to fire

X

XP

Using Office 2003 and Windows XP;

I have the following event in ThisWorkbook:

Private Sub Workbook_Open()
Call FileOpenRequest
End Sub

In the above, FileOpenRequest is a function that first unhides a sheet and
very hides a couple others, turns on sheet protection without any password,
and a few other pretty basic settings so the opening sheet will look right
for the user.

The first time I open this file Workbook_Open runs perfectly. The second
time I open the file in the same instance of Excel, Workbook_Open fails to
fire. It is as though macros are disabled, even though they are not. Security
is set to medium and it asks if macros should be enabled, of course I open
with macros enabled.

After the file loads, I can open the VBE and manually run the code and it
runs fine. If I close Excel completely and open a new instance, it runs fine
the first time, then it will never fire again in that instance.

Does anyone have a clue why it is failing like this? And, more importantly,
how the heck to fix it?

Thanks much in advance for your assistance.
 
J

Joel

Add a message box to the code below. When the workbook opens and the box
appears you can type CNTL Break to debug the code.


Private Sub Workbook_Open()
msgbox("opened workbook")
Call FileOpenRequest
End Sub
 
X

XP

Okay, Joel. I think I discovered what is happening.

I have:

Application.EnableEvents = False
 
J

Joel

Nothing will run after the line "ThisWorkbook.Close" because when the
workbook is closed the macro stops running.

The code below is better, but if the Save fails the events are not enabled

ThisWorkbook.Save
Application.EnableEvents = True
ThisWorkbook.Close

This is even better

On Error go to finish
ThisWorkbook.Save
Application.EnableEvents = True
ThisWorkbook.Close
exit sub
finish:msgbox("Error: Failed to Save Thisworkbook")
Application.EnableEvents = True
end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top