awsumchillicrab
Board Regular
- Joined
- Jan 30, 2011
- Messages
- 56
I'm trying to make a macro run whenever any workbook is opened, regardless of whether Excel is open already. This is what I have in my PERSONAL.XLSM vba project:
Class1:
ThisWorkbook:
This doesn't work at all as subsequent workbooks I open don't show the Msgbox "Brand new workbook opened" or "Existing workbook opened". I'm guessing it's because the "Set myobject.ExcelApp = Application" has to be contained in a Module instead of ThisWorkbook. If that's true, how do I get code in a Module to automatically run?
And if it's not true, then how do I resolve this?
Class1:
Option Explicit
Public WithEvents ExcelApp As Application
Private Sub ExcelApp_NewWorkbook(ByVal Wb As Workbook)
MsgBox "Brand new workbook opened"
End Sub
Private Sub ExcelApp_WorkbookOpen(ByVal Wb As Workbook)
MsgBox "Existing workbook opened"
End Sub
ThisWorkbook:
Option Explicit
Private Sub Workbook_Open()
Dim myobject As New Class1
MsgBox "The Personal.xlsm workbook is opened, auto macro activated!"
Set myobject.ExcelApp = Application
End Sub
This doesn't work at all as subsequent workbooks I open don't show the Msgbox "Brand new workbook opened" or "Existing workbook opened". I'm guessing it's because the "Set myobject.ExcelApp = Application" has to be contained in a Module instead of ThisWorkbook. If that's true, how do I get code in a Module to automatically run?
And if it's not true, then how do I resolve this?