Option
Explicit
Const
ShName
As
String
=
"Variables"
Dim
WS
As
Worksheet
Public
Var1
As
String
Public
Var2
As
Double
Private
Sub
Class_Initialize()
Dim
x
As
Worksheet
Dim
Exists
As
Boolean
For
Each
x
In
ThisWorkbook.Worksheets
If
x.Name = ShName
Then
Exists =
True
Exit
For
End
If
Next
If
Exists
Then
Set
WS = Sheets(ShName)
LoadVariables
Else
Set
WS = Sheets.Add
WS.Name = ShName
End
If
End
Sub
Private
Sub
Class_Terminate()
SaveVariables
End
Sub
Public
Property
Let
PropVar1(value
As
String
)
WS.Cells(1, 1).value = value
End
Property
Public
Property
Let
PropVar2(value
As
String
)
WS.Cells(2, 1).value = value
End
Property
Public
Property
Get
PropVar1()
As
String
PropVar1 = WS.Cells(1, 1).value
End
Property
Public
Property
Get
PropVar2()
As
String
PropVar2 = WS.Cells(2, 1).value
End
Property
Public
Property
Let
SheetVisible(value
As
XlSheetVisibility)
WS.Visible = value
End
Property
Public
Sub
LoadVariables()
With
WS
Var1 = .Cells(1, 1).value
Var2 = .Cells(2, 1).value
End
With
End
Sub
Public
Sub
SaveVariables()
With
WS
.Cells(1, 1).value = Var1
.Cells(2, 1).value = Var2
End
With
End
Sub