I've created an Excel add-in that attempts to run upon the opening of any and all workbooks that are opened during this session. It works sometimes - but not always, and I don't know why.
I created a file, addin.xlam
, and in this file, in ThisWorkbook
, I have:
Private XLApp As CExcelEvents
Private Sub Workbook_Open()
Set XLApp = New CExcelEvents
End Sub
I then created a class module based off the code here: http://www.cpearson.com/Excel/AppEvent.aspx
Private WithEvents App As Application
Private Sub Class_Initialize()
Set App = Application
End Sub
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
If Not ActiveWorkbook Is Nothing Then
If InStr(ActiveWorkbook.Name, "New Quote") Then
quoteCheck = MsgBox("Do you want to run the Quote Generator?", vbYesNo, "Quote Generator")
If quoteCheck = vbYes Then
prepare
Else
End
End If
End If
End If
End Sub
If I close out of Excel and open a file from Windows Explorer, this line hits:
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
And starts the code - if the workbook in question has "new quote" in its name, the macro runs. Boom. Perfect.
However, after this runs ONCE, if I open another workbook with the words "new quote", this private sub doesn't trigger. Why?
How do I get this to trigger each time I open any workbook?