Hi guys and gals,
as in the topic : On Error run Private Sub Workbook_Open() <-- is this possible?
Thanks for any reply!
Hi guys and gals,
as in the topic : On Error run Private Sub Workbook_Open() <-- is this possible?
Thanks for any reply!
Please click the * below if this helps
Private Sub Workbook_Open() will only execute when you open your workbook. You can achieve this by writing another sub routine like Private Sub MyCode() where you can place the code of workbook_open by copying the code between Private Sub Workbook_Open() and End Sub lines and placing it between the lines Private Sub MyCode() and End Sub. Then you can call Mycode if an error occurs in your another sub routine.
Like this.....
Private Sub CallingCode() On Error Resume Next 'Here is the line of code which may produce an error If Err>0 Then MyCode Else 'whatever you want to do if there is no error End If Err=0 End Sub
Regards
sktneer
Treat people the way you want to be treated. Talk to people the way you want to be talked to.
Respect is earned NOT given.
I was afraid so....
Thanks for your feedback!
That's not correct. Workbook_Open is a routine like any other. As it has Private scope you have to use Run to call it but you can't do it in one line as an On Error statement - you would have to have a goto statement and run it from there:
for example.On Error GoTo err_handler Err.Raise 1 Exit Sub err_handler: Application.Run "Thisworkbook.Workbook_Open"
Having said that, if you want to call the same code from two locations, you should put it into a separate routine and call that from both locations.
Everyone who confuses correlation and causation ends up dead.
Hi Rory,
awesome, thanks!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks