Workbook_Open sub won't run when I open the workbook?

后端 未结 6 586
自闭症患者
自闭症患者 2020-12-11 01:07

This program is supposed to create a button that the user can press to activate a different sub. From my searches online, it seems that the sub below should activate when op

6条回答
  •  不思量自难忘°
    2020-12-11 01:34

    Interesting. In 2009 a conflict with conditional formatting of the sheet to open is described, as in vbforum post.

    It seems that this bug still exists in excel and prevents the workbook_open event from being fired. I have a workbook (old XLS-binary format) that simply does not fire the event in Excel 2003 and 2007 but does in 2013. I deleted all conditional formatting from the first worksheet but could still not get the workbook_open procedure to run in elder Excel-Versions.

    A Workaround, I use in distributed workbooks is to use a local variable and a second event in the workbook as follows:

    ''
    ' private variable
    Private wbOpenEventRun as Boolean
    
    ''
    ' procedure to be called by excel when workbook opens
    Private Sub Workbook_Open()
        wbOpenEventRun = true
        ' perform tasks
    End Sub
    
    ''
    ' the selection change event fires usually.
    ' performance is not reduced
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
        If Not wbOpenEventRun Then Workbook_Open
        ' perform tasks in reaction of selection change events, if required
    End Sub
    

提交回复
热议问题