If you want to use these values, such as constants , that will have the same value all the time, you can still define them as private members of the ThisWorkbook class and implement the get property, which reconfigures the value and ensures that the value is defined.
The advantage of this solution is that no one except the ThisWorkbook object can change the values ββof these variables. This does not apply to publicly-accessible global variables, because someone might accidentally, for example. set workbook1 to Nothing , and since Workbook_Open only starts once from the very beginning, an error will occur when accessing workbook1 . IMO for using global variables is basically not a good idea. NTN
ThisWorkbook class module:
Option Explicit Private m_worksheet1 As Worksheet Private m_array1 As Variant Public Property Get Worksheet1() As Worksheet If m_worksheet1 Is Nothing Then _ Set m_worksheet1 = ThisWorkbook.Worksheets("Sheet 1") Set Worksheet1 = m_worksheet1 End Property Public Property Get Array1() As Variant If Not IsArray(m_array1) Then _ m_array1 = Array(3, 5, 6, 7, 5) Array1 = m_array1 End Property
Then everywhere in the book, just call the property on ThisWorkbook , for example. like this.
Debug.Print UBound(ThisWorkbook.Array1) Debug.Print ThisWorkbook.Worksheet1.Name
Output:
4 Sheet 1
source share