Share via

Excel Workbook_Open() does not run when another workbook is open

Anonymous
2022-11-02T17:38:47+00:00

Here is some code. It works perfect unless you open it if there is an excel workbook open.

Private Sub Workbook_Open()

Application.ThisWorkbook.Activate 

Application.EnableEvents = True 

Application.ScreenUpdating = True 

Application.DisplayAlerts = True 

FileTAC 

End Sub

In a different module i have:

Public Function FileTAC()

Dim MSG As String 

Application.DisplayAlerts = True 

Application.ScreenUpdating = True 

MSG = "No changes or substitutions will be" & vbCrLf 

MSG = MSG & "accepted after 12:00 PM the" & vbCrLf 

MSG = MSG & "day prior to the scheduled" & vbCrLf 

MSG = MSG & "appointment. Call extension 7705" & vbCrLf 

MSG = MSG & "for more information." & vbCrLf 

MSG = MSG & vbCrLf 

MSG = MSG & "Click Yes if you understand." & vbCrLf 

If MsgBox(MSG, vbInformation + vbYesNo) = vbNo Then 

    B4Action 

    AppClose 

    GoTo Done 

Else 

    MacrosAreActive 

    GoTo Done: 

End If 

Done:

Application.DisplayAlerts = True 

Application.ScreenUpdating = True 

Exit Function 

End Function

Public Function B4Action()

Application.DisplayAlerts = False 

Application.ScreenUpdating = False 

Dim ws As Excel.Worksheet 

For Each ws In ThisWorkbook.Worksheets 

Select Case ws.Name 

    Case "Macros" 

        Worksheets("Macros").Visible = True 

        ThisWorkbook.Sheets("Macros").Select 

    Case Else 

        ws.Visible = False 

End Select 

Next ws 

GoTo Done 

Done:

Application.DisplayAlerts = True 

Application.ScreenUpdating = True 

Exit Function 

End Function

Public Function MacrosAreActive()

Application.DisplayAlerts = False 

Application.ScreenUpdating = False 

Dim ws As Excel.Worksheet 

For Each ws In ThisWorkbook.Worksheets 

    ws.Visible = True 

Next ws 

ThisWorkbook.Sheets("Macros").Visible = xlSheetVeryHidden 

GoTo Done 

Done:

Application.DisplayAlerts = True 

Application.ScreenUpdating = True 

Exit Function 

End Function

Public Function AftSave()

Dim MSG As String 

MSG = MSG & "File Saved. Do you wish to close?" & vbCrLf 

If MsgBox(MSG, vbInformation + vbYesNo) = vbYes Then 

    AppClose 

Else 

    MacrosAreActive 

End If 

GoTo Done 

Done:

Exit Function 

End Function

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2022-11-02T18:09:01+00:00

Look in other workbooks for code that finishes after setting Application.EnableEvents = False without resetting it to True, or run this code before opening the workbook:

Sub ResetEvents()

Application.EnableEvents = True

End Sub

Note that these two lines are not needed in your open event: workbooks being opened are automatically active, and events must be enabled (set to True) for the code to run.

Application.ThisWorkbook.Activate

Application.EnableEvents = True

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2022-11-02T21:28:15+00:00

    Thank you. I found the issue. In my module to close the application for some unknown reason, (completely my fault) I had put

    Application.EnableEvents = True

    after

    ThisWorkbook.Close

    The two lines you said are not needed I did remove. I had placed them in as an effort to fix the issue I was having with mutiple workbooks open.

    Thank you again for show me my error!

    Was this answer helpful?

    0 comments No comments