1
1
Attribute VB_Name = "Installer"
2
-
3
2
Option Explicit
4
3
5
4
'1) Create an Excel file called Installer.xlsm in same folder than Installer.bas:
@@ -24,7 +23,7 @@ Option Explicit
24
23
25
24
'6) Make step 3a and 3b again for this file and run the sub testImport located in the module "Build".
26
25
27
- Public Const addin_name = "vbaDeveloper"
26
+ Public Const TOOL_NAME = "vbaDeveloper"
28
27
29
28
Sub AutoInstaller ()
30
29
@@ -33,10 +32,10 @@ Sub AutoInstaller()
33
32
End Sub
34
33
Sub AutoInstaller_step0 ()
35
34
36
- 'Close the vbaDevelopper Workbook if already open and uninstall
35
+ 'Close the vbaDevelopper Workbook if already open and uninstall from addins
37
36
On Error Resume Next
38
- Workbooks(addin_name & ".xlam" ).Close
39
- Application.AddIns2(AddinName2index(addin_name & ".xlam" )).Installed = False
37
+ Workbooks(TOOL_NAME & ".xlam" ).Close
38
+ Application.AddIns2(AddinName2index(TOOL_NAME & ".xlam" )).Installed = False
40
39
On Error GoTo 0
41
40
42
41
Application.OnTime Now + TimeValue("00:00:06" ), "AutoInstaller_step1"
@@ -59,7 +58,7 @@ strPathOfBuild = CurrentWB.Path & "\src\vbaDeveloper.xlam\Build.bas"
59
58
NewWB.VBProject.VBComponents.Import strPathOfBuild
60
59
61
60
'Rename the project (in the VBA) to vbaDeveloper
62
- NewWB.VBProject.Name = addin_name
61
+ NewWB.VBProject.Name = TOOL_NAME
63
62
64
63
'Add references to the library
65
64
'Microsoft Scripting Runtime
@@ -73,14 +72,14 @@ NewWB.VBProject.VBComponents.Import strPathOfBuild
73
72
'In VB Editor, menu File-->Save Book1; Save as vbaDeveloper.xlam in the same directory as 'src'
74
73
75
74
strLocationXLAM = CurrentWB.Path
76
- NewWB.SaveAs strLocationXLAM & "\" & addin_name & ".xlam" , xlOpenXMLAddIn
75
+ NewWB.SaveAs strLocationXLAM & "\" & TOOL_NAME & ".xlam" , xlOpenXMLAddIn
77
76
78
77
'Close excel. Open excel with a new workbook, then open the just saved vbaDeveloper.xlam
79
78
NewWB.Close savechanges:=False
80
79
81
80
'Add the Add-in (if not already present)
82
- If IsAddinInstalled(addin_name ) = False Then
83
- Call Application .AddIns2 .Add (strLocationXLAM & "\" & addin_name & ".xlam" , CopyFile:=False )
81
+ If IsAddinInstalled(TOOL_NAME & ".xlam" ) = False Then
82
+ Call Application .AddIns2 .Add (strLocationXLAM & "\" & TOOL_NAME & ".xlam" , CopyFile:=False )
84
83
End If
85
84
86
85
'Continue to step 2
@@ -91,7 +90,7 @@ End Sub
91
90
Sub AutoInstaller_step2 ()
92
91
93
92
'Install the Addin (This should open the file)
94
- Application.AddIns2(AddinName2index(addin_name & ".xlam" )).Installed = True
93
+ Application.AddIns2(AddinName2index(TOOL_NAME & ".xlam" )).Installed = True
95
94
96
95
Application.OnTime Now + TimeValue("00:00:02" ), "AutoInstaller_step3"
97
96
@@ -113,9 +112,9 @@ Sub AutoInstaller_step4()
113
112
'Run the Workbook_Open macro from vbaDeveloper
114
113
Application.Run "vbaDeveloper.xlam!Menu.createMenu"
115
114
116
- Workbooks(addin_name & ".xlam" ).Save
115
+ Workbooks(TOOL_NAME & ".xlam" ).Save
117
116
118
- MsgBox addin_name & " was successfully installed."
117
+ MsgBox TOOL_NAME & " was successfully installed."
119
118
120
119
End Sub
121
120
@@ -140,3 +139,41 @@ Function AddinName2index(ByVal addin_name As String) As Integer
140
139
'If we get to this line, it means no match was found
141
140
AddinName2index = 0
142
141
End Function
142
+
143
+ Sub AutoAssembler ()
144
+
145
+ 'Prepare variable
146
+ Dim CurrentWB As Workbook , NewWB As Workbook
147
+
148
+ Dim textline As String , strPathOfBuild As String , strLocationXLAM As String
149
+
150
+ 'Set the variables
151
+ Set CurrentWB = ThisWorkbook
152
+ Set NewWB = Workbooks.Add
153
+
154
+ 'Import code form Build.bas to the new workbook
155
+ strPathOfBuild = CurrentWB.Path & "\src\vbaDeveloper.xlam\Build.bas"
156
+ NewWB.VBProject.VBComponents.Import strPathOfBuild
157
+
158
+ 'Rename the project (in the VBA) to vbaDeveloper
159
+ NewWB.VBProject.Name = TOOL_NAME & "_pkg"
160
+
161
+ 'Add references to the library
162
+ 'Microsoft Scripting Runtime
163
+ NewWB.VBProject.References.AddFromGuid "{420B2830-E718-11CF-893D-00A0C9054228}" , 1 , 0
164
+
165
+ 'Microsoft Visual Basic for Applications Extensibility 5.3
166
+ NewWB.VBProject.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}" , 5 , 3
167
+
168
+ 'Save file as .xlsm
169
+ strLocationXLAM = CurrentWB.Path
170
+ NewWB.SaveAs strLocationXLAM & "\" & TOOL_NAME & "_pkg" & ".xlsm" , xlOpenXMLWorkbookMacroEnabled
171
+
172
+ 'Close excel. Open excel with a new workbook, then open the just saved vbaDeveloper.xlsm
173
+ NewWB.Close savechanges:=False
174
+
175
+ 'Run the Build macro in vbaDeveloper
176
+ Application.Run "vbaDeveloper.xlsm!Build.testImport"
177
+
178
+ End Sub
179
+
0 commit comments