-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWorksheetsClass.cls
136 lines (100 loc) · 3.45 KB
/
WorksheetsClass.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "WorksheetsClass"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'@Folder("TableManager.Worksheets")
Option Explicit
Private Const Module_Name As String = "WorksheetsClass."
Private pAllSheets As Scripting.Dictionary
Private Sub Class_Initialize()
Debug.Assert Initializing
Set pAllSheets = New Scripting.Dictionary
End Sub ' Class_Initialize
Private Function ModuleList() As Variant
ModuleList = Array("XLAM_Module.", "WorksheetRoutines.")
End Function ' ModuleList
Public Property Get Count() As Long: Count = TableCount(pAllSheets.Count): End Property
'@DefaultMember
Public Property Get Item( _
ByVal vIndex As Variant, _
ByVal ModuleName As String) As WorksheetClass
'Attribute Item.VB_UserMemId = 0
Const RoutineName As String = Module_Name & "Get_Item"
Debug.Assert InScope(ModuleList, ModuleName)
On Error GoTo ErrorHandler
On Error Resume Next
Set Item = pAllSheets.Items()(vIndex)
If Err.Number = 0 Then
On Error GoTo 0
Exit Property
End If
On Error Resume Next
Set Item = pAllSheets(vIndex)
On Error GoTo 0
Debug.Assert Not Item Is Nothing
'@Ignore LineLabelNotUsed
Done:
Exit Property
'@Ignore LineLabelNotUsed
ErrorHandler:
RaiseError Err.Number, Err.Source, RoutineName, Err.Description
End Property
Public Sub Add( _
ByVal Sht As WorksheetClass, _
ByVal ModuleName As String)
Dim Evt As EventClass
Const RoutineName As String = Module_Name & "Add"
Debug.Assert Initializing
Debug.Assert InScope(ModuleList, ModuleName)
On Error GoTo ErrorHandler
Set Evt = New EventClass
If Sht.Name <> vbNullString Then
pAllSheets.Add Sht.Name, Sht
Set Evt.SheetEvent = Sht.Worksheet
Set pAllSheets.Item(Sht.Worksheet.Name).WorksheetEvent.SheetEvent = Sht.Worksheet
End If
'@Ignore LineLabelNotUsed
Done:
Exit Sub
ErrorHandler:
RaiseError Err.Number, Err.Source, RoutineName, Err.Description
End Sub ' Add
Public Sub Remove( _
ByVal vIndex As Variant, _
ByVal ModuleName As String)
Const RoutineName As String = Module_Name & "Remove"
Debug.Assert InScope(ModuleList, ModuleName)
On Error GoTo ErrorHandler
If CStr(vIndex) = "*" Then
WorksheetSetNothing Module_Name
WorksheetSetNewDict Module_Name
Else
If Not WorksheetExists(vIndex, Module_Name) Then Err.Raise 9
pAllSheets.Remove vIndex
End If
'@Ignore LineLabelNotUsed
Done:
Exit Sub
ErrorHandler:
RaiseError Err.Number, Err.Source, RoutineName, Err.Description
End Sub ' Remove
Public Function Exists( _
ByVal vIndex As Variant, _
ByVal ModuleName As String _
) As Boolean
' Used in TableRoutines
Const RoutineName As String = Module_Name & "Exists"
On Error GoTo ErrorHandler
Debug.Assert InScope(ModuleList, ModuleName)
Exists = pAllSheets.Exists(vIndex)
'@Ignore LineLabelNotUsed
Done:
Exit Function
ErrorHandler:
RaiseError Err.Number, Err.Source, RoutineName, Err.Description
End Function ' Exists