Excel Workbook Open Event macro doesn't always run

后端 未结 10 571
刺人心
刺人心 2020-12-11 04:23

I\'ve got a Workbook_Open event macro (and it\'s in ThisWorkbook) that doesn\'t always run.

  • If Excel is closed and I double-click the .xls file from Windows Ex
10条回答
  •  离开以前
    2020-12-11 04:40

    To add to the Arturo Llano post: The following code was used to monitor the Workbook_Open event and then run ProcessX whenever a workbook was opened.

    ProcessX contained an End statement. The result was that it worked only the first time. The End wiped out AppX, so there was no further monitoring of events. Removing End fixed the problem. (Using End is bad practice anyway as it stops everything without any kind of cleanup or termination of other resources).

    'Code in: Personal.xlsb ThisWorkbook

    Public WithEvents AppX As Application
    
    Private Sub Workbook_Open()
    
       Set AppX = Application
    
    End Sub
    
    Private Sub AppX_WorkbookOpen(ByVal wb As Workbook)
    
      'A 1-second delay to allow opening to complete before ProcessX starts.
    
       Application.OnTime Now + TimeValue("00:00:01"), "ProcessX"
    
    End Sub
    

提交回复
热议问题