Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Workbook_Open event fails to fire

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Workbook_Open event fails to fire

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


"XP" wrote:

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Workbook_Open event fails to fire

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

I have:

Application.EnableEvents = False
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Workbook_Open event fails to fire

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


"XP" wrote:

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

I have:

Application.EnableEvents = False
.
.
<some other code here
.
ThisWorkbook.Save: ThisWorkbook.Close
Application.EnableEvents = True

But, I bet once the file is saved and closed, the line to enable events
doesn't take, thereby killing the macros on the next open. Am I right?

How can I trap and control a close like this? I need the code to display a
blank sheet on the way out in case the file is opened with macros disabled,
etc.

BTW, thanks for your help.


"Joel" wrote:

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


"XP" wrote:

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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
event fire Curt Excel Programming 19 March 7th 07 12:29 AM
Excel 97 fails to execute Workbook_Open() on New XLS from Template (FYI) [email protected] Excel Programming 1 March 3rd 07 11:39 AM
Private Sub Workbook_Open() event won't fire if workbook is hidden? Mike Weaver Excel Programming 2 February 15th 06 01:38 PM
Event doesn't fire Frank Xia Excel Discussion (Misc queries) 6 February 11th 06 12:54 AM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


All times are GMT +1. The time now is 02:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"