-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXLAM_Module.bas
140 lines (100 loc) · 3.59 KB
/
XLAM_Module.bas
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
135
136
137
138
Attribute VB_Name = "XLAM_Module"
'@Folder("TableManager.Main")
Option Explicit
Private Const Module_Name As String = "XLAM_Module."
Private Init As Boolean
Private pMainWorkbook As Workbook
Private LastControl As control
' TODO Implement more specific error messages
Public Enum CustomError
Success = 0
[_First] = vbObjectError - 10000
ArrayMustBe1or2Dimensions ' description
CustomErrorTwo ' description
' ... more error names
[_Last]
End Enum
Public Function NewWorkbookClass() As WorkbookClass
Set NewWorkbookClass = New WorkbookClass
End Function
Public Sub SetLastControl(ByVal Ctl As control)
Set LastControl = Ctl
End Sub
Public Function GetLastControl() As control
Set GetLastControl = LastControl
End Function
Public Function GetMainWorkbook() As Workbook
Const RoutineName As String = Module_Name & "GetMainWorkbook"
On Error GoTo ErrorHandler
Set GetMainWorkbook = pMainWorkbook
'@Ignore LineLabelNotUsed
Done:
Exit Function
ErrorHandler:
RaiseError Err.Number, Err.Source, RoutineName, Err.Description
End Function
Public Sub SetMainWorkbook(ByVal Wkbk As Workbook)
Set pMainWorkbook = Wkbk
End Sub
Public Function GetWorkBookPath(ByVal Wkbk As Workbook) As String
GetWorkBookPath = Wkbk.Path
End Function
Public Sub InitializeWorkbookForTableManager(ByVal Wkbk As Workbook, _
Optional ByVal KeepUserForms As Boolean = True)
Const RoutineName As String = Module_Name & "InitializeWorkbookForTableManager"
On Error GoTo ErrorHandler
SetInitializing
If Not CheckForVBAProjectAccessEnabled(Wkbk) Then
MsgBox "You must set the project access for the " & _
"TableManager Add-In to work", _
vbOKOnly Or vbCritical, _
"Project Access"
Stop
End If
If Not KeepUserForms Then
Set pMainWorkbook = Wkbk
' Delete all the old UserForms from TableManager
' I haven't found a way to create and add a new userform to another workbook
Dim UserFrm As Object
For Each UserFrm In ThisWorkbook.VBProject.VBComponents
If UserFrm.Type = vbext_ct_MSForm And _
Left$(UserFrm.Name, 8) = "UserForm" _
Then
ThisWorkbook.VBProject.VBComponents.Remove UserFrm
End If
Next UserFrm
WorksheetSetNewClass Module_Name
TableSetNewClass Module_Name
End If
' Go through all the worksheets and all the tables on each worksheet
' collecting the data and building the form for each table
Dim WkSht As WorksheetClass
Dim Sht As Worksheet
Dim TblObj As ListObject
For Each Sht In Wkbk.Worksheets
Set WkSht = New WorksheetClass
Set WkSht.Worksheet = Sht
WkSht.Name = Sht.Name
WorksheetAdd WkSht, Module_Name
For Each TblObj In Sht.ListObjects
BuildTable Wkbk, TblObj, Module_Name
Next TblObj
Next Sht
DoEvents
ReSetInitializing
'@Ignore LineLabelNotUsed
Done:
Exit Sub
ErrorHandler:
RaiseError Err.Number, Err.Source, RoutineName, Err.Description
' DisplayError RoutineName
End Sub ' InitializeWorkbookForTableManager
Public Function Initializing() As Boolean
Initializing = Init
End Function ' Initializing
Public Sub SetInitializing()
Init = True
End Sub
Public Sub ReSetInitializing()
Init = False
End Sub