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
Similar to Nazim's event enable via code solution I found out the following fix:
closing all excel workbooks and VBA windows and reopening the one with Workbook_Open()
solved it.
(likely due to the event enabling similar to Nazim's solution linked above).
As I was debugging and aborted execution, I disabled the events in the running code before abort. I did not notice this circumstance at first and even after close/reopen of my workbook it did not work...
...The other open excel workbooks or some global instance somehow "remembered" that the events of the reopened workbook had been turned off.
I know this post has been dormant for a while, but I just struggled for hours to solve this problem. It's the oddest thing, but I finally noticed that one of my worksheets was in "Page View"... and as soon as I put it into "Normal" my Workbook_Open() function started working as normal again. VERY STRANGE - definitely a Excel bug... just glad I finally solved it... Hope it helps someone...
The solution I found was running the below code and then the "Open" event worked.
Sub EventRestore()
Application.EnableEvents = True
End Sub
Make sure your Private Sub Workbook_Open() subroutine is pasted inside of the This Workbook object and not in a Module, Form, or Sheet object.
My solution was kind of obscure, and I don't even remember now why it occurred to me as a potential solution. The file I created in which the Workbook_Open() macro would not run, I originally created through the following steps:
For whatever reason, I wondered if my problem had anything to do with the fact that the file "started as" a standard .xlsx. So I simply:
Unlike the original Workbook_1, the new Workbook_2 successfully ran the Workbook_Open() sub on open. Maybe a potential cause of this problem is related to the file's type history (i.e. if it was at some point a type that cannot run macros). Or maybe simply trying again with a new file is what solved this problem for me. Either way, this may work for anyone for which other solutions did not.
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