I know I’ve done this before, but for the life of me, I can’t figure it out now!
I am building an Excel app as a template. I have a button in the template labelled “New File” which should create a new workbook based on the same template. When the new workbook is created, I want the NewWorkbook event to fire.
I have created a new class called clsEvents with this code:
Public WithEvents App As Application
Private Sub App_NewWorkbook(ByVal Wb As Workbook)
‘this never fires
MsgBox “new workbook event fired”
End Sub
The problem is that I don’t know where to place the global variable to hold a pointer to my clsEvents.App object. Right now its in a module called Main:
Dim AppObject As New clsEvents
Sub Init()
Set AppObject.App = Application
End Sub
…. but where should I call the Init() from?? Right now I’m calling it from ThisWorkBook.Workbook_Open.