Resetting workbookopen code after error

kgartin

Board Regular
Joined
May 6, 2010
Messages
201
I have a code set to run when any workbook opens. It's set on Personal>ThisWorkbook.

Works flawlessly until there's any kind of error and then I have to close and reopen the Excel app to get it to work again. Is there another way to reset without restarting the app?


Thanks!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
What kind of errors are you getting?
What does the code look like?
You may be able to add error handling to your code to gracefully handle them.
 
Upvote 0
What kind of errors are you getting?
What does the code look like?
You may be able to add error handling to your code to gracefully handle them.

The error code isn't associated with the WorkbookOpen code. It can be any error at all that causes the code to no longer function when a workbook opens until the app is closed and restarted.

Here's the full code that may help:

Code:
Private Sub app_WorkbookOpen(ByVal WB As Workbook)
WBC = Application.Workbooks.COUNT


Dim JOBNUM As Integer, JROW As Integer


If WBC < 3 Then Exit Sub


'If ActiveWorkbook.ActiveSheet.Range("B4") = "LAYOUT" Then GoTo Skip


'Dim WB As Workbook
On Error Resume Next
    Set WB = Workbooks(Year(Date) & " Com Forecast (544).xlsm")
    If Err Then Exit Sub 'MsgBox "The workbook is not open"
    If WB.Worksheets("START DATE").Range("R7") = False Then Exit Sub
On Error GoTo 0
 
Skip:
    'If ActiveWorkbook.ActiveSheet.Range("B4") = "LAYOUT" Then Call SAVE_COLORPOS
    If ActiveWorkbook.ActiveSheet.Range("K2") = "Person In Charge" Then Call COPYPREP_COPY
    If ActiveWorkbook.ActiveSheet.Range("B1") = "COMMERCIAL DISTRIBUTION INFORMATION REPORT" Then Call DIST_COPYPREP_COPY
    If ActiveWorkbook.ActiveSheet.Range("B4") = "Commercial Billing Sheet" Or ActiveWorkbook.ActiveSheet.Range("D21") = "Sold To:" Then
        Application.Windows.Arrange ArrangeStyle:=xlHorizontal
        If Range("A3") = "" Then GoTo Getout
        JOBNUM = Range("A3").Value
        WB.Activate
        JROW = Application.Match(JOBNUM, WB.Worksheets("YTD").Range("E:E"), 0) - 2
        ActiveWindow.ScrollRow = JROW
    End If
    
Getout:
End Sub
 
Upvote 0
Sorry, I did not realize that you were working with Application events (and not Workbook events), and I do not really have any experience with them.
I am not sure if it helps, but I found this here: http://www.cpearson.com/excel/AppEvent.aspx
 
Upvote 0
How exactly does it stop working?

Is the code not being executed the next time you open a workbook?
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,928
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top