tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,832
- Office Version
- 365
- 2019
- Platform
- Windows
Can someone please explain the difference between these two ideas:
Idea 1:
This is in ThisWorkbook:
This is in Class1:
Idea 2:
This is in ThisWorkbook:
This is in Class1:
The differences being between Sub Workbook_Open(), where one is:
and the other:
Also in Class1, WithEvents is declared as Private in the First but Public in the second.
Both First and Second work, so what impact do the differences have?
Thanks
Idea 1:
This is in ThisWorkbook:
Code:
Option Explicit
Private abc As Class1
Private Sub Workbook_Open()
Set abc = New Class1
End Sub
This is in Class1:
Code:
Option Explicit
Private WithEvents xlApp As Application
Private Sub Class_Initialize()
Set xlApp = Application
End Sub
Private Sub xlApp_NewWorkbook(ByVal Wb As Workbook)
Wb.Worksheets("Sheet1").Range("A1").Value = "Created on " & Date
End Sub
Idea 2:
This is in ThisWorkbook:
Code:
Option Explicit
Private abc As New Class1
Private Sub Workbook_Open()
Set abc.xlApp = Application
End Sub
This is in Class1:
Code:
Option Explicit
Public WithEvents xlApp As Application
Private Sub Class_Initialize()
Set xlApp = Application
End Sub
Private Sub xlApp_NewWorkbook(ByVal Wb As Workbook)
Wb.Worksheets("Sheet1").Range("A1").Value = "Created on " & Date
End Sub
The differences being between Sub Workbook_Open(), where one is:
Code:
Set abc = New Class1
and the other:
Code:
Set abc.xlApp = Application
Also in Class1, WithEvents is declared as Private in the First but Public in the second.
Both First and Second work, so what impact do the differences have?
Thanks