XL97 Private Sub Workbook_Open() Not Working

P

Pete

Question, why did Private Sub Workbook_Open()
not work?

I have used it many times before and it worked fine.

But on this project it would not work, but if I put in an
Sub Auto_Open () routine it works fine.

---- this does not work in the ThisWorkbook

Private Sub Workbook_Open()
MsgBox "Application Opened ThisWorkbook" ' put in to debug
Display_UnitInfo
End Sub

----- But this does work on Module1

Sub Auto_Open()
Display_UnitInfo
MsgBox "Application Opened ThisWorkbook" ' put in to debug
End Sub

I can live with it, but curious why as to the Workbook_Open()
stopped working in this project.
 
B

Bob Phillips

Is there any rationale behind the fact that the code statements are
reversed?

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
T

Tushar Mehta

Did you at some point execute a 'Application.EnableEvents=False'
statement and not reverse the effect? EnableEvents doesn't affect the
Auto_Open routine.


--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
P

Pete

Did you at some point execute a 'Application.EnableEvents=False'
statement and not reverse the effect? EnableEvents doesn't affect the
Auto_Open routine.

Yes I did but then took it out.

Seems strange. I am redoing this from scratch and importing the sheets and
routines one by one to try and pin point where this is occuring.
 
T

Tushar Mehta

Yes I did but then took it out.

Seems strange. I am redoing this from scratch and importing the sheets and
routines one by one to try and pin point where this is occuring.
No, nothing strange. EnableEvents is a persistent setting that XL
remembers for the duration that it is running. Too many use (or
recommend) EnableEvents=False without realizing how long lasting its
effect can be. IMO, the only safe way to use it is within the
equivalent of VB.Net's Try...Catch...Finally structure. In VBA, the
closest would be:

'...
On Error Goto CleanUp
Application.EnableEvents=False
'...
CleanUp:
Application.EnableEvents=True
End Sub
--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
P

Pete

No, nothing strange. EnableEvents is a persistent setting that XL
remembers for the duration that it is running. Too many use (or
recommend) EnableEvents=False without realizing how long lasting its
effect can be. IMO, the only safe way to use it is within the
equivalent of VB.Net's Try...Catch...Finally structure. In VBA, the
closest would be:

'...
On Error Goto CleanUp
Application.EnableEvents=False
'...
CleanUp:
Application.EnableEvents=True
End Sub

Thanks I will try that. And when I opened a new workbook and copied all
the sheets to it along with the vba code minus the enableevents, it works
fine now.

Thanks again!
 

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