ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   XL97 Private Sub Workbook_Open() Not Working (https://www.excelbanter.com/excel-programming/327671-xl97-private-sub-workbook_open-not-working.html)

pete

XL97 Private Sub Workbook_Open() Not Working
 
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.




Bob Phillips[_6_]

XL97 Private Sub Workbook_Open() Not Working
 
Is there any rationale behind the fact that the code statements are
reversed?

--

HTH

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


"Pete" wrote in message
...
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.






Tushar Mehta

XL97 Private Sub Workbook_Open() Not Working
 
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

In article ,
says...
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.





pete

XL97 Private Sub Workbook_Open() Not Working
 
Tushar Mehta wrote in
om:

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.

pete

XL97 Private Sub Workbook_Open() Not Working
 
"Bob Phillips" wrote in
:

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


Nope, just inserted them to see for myself if the code was working.


Tushar Mehta

XL97 Private Sub Workbook_Open() Not Working
 
In article ,
says...
Tushar Mehta wrote in
om:

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.

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

pete

XL97 Private Sub Workbook_Open() Not Working
 
Tushar Mehta wrote in
om:

In article ,
says...
Tushar Mehta wrote in
om:

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.

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!


All times are GMT +1. The time now is 07:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com