Skip to content

Commit 1bcc76f

Browse files
committed
Installer.bas - Allow for assembling as .xlsm
1 parent 535a1dd commit 1bcc76f

File tree

1 file changed

+49
-12
lines changed

1 file changed

+49
-12
lines changed

Installer.bas

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Attribute VB_Name = "Installer"
2-
32
Option Explicit
43

54
'1) Create an Excel file called Installer.xlsm in same folder than Installer.bas:
@@ -24,7 +23,7 @@ Option Explicit
2423

2524
'6) Make step 3a and 3b again for this file and run the sub testImport located in the module "Build".
2625

27-
Public Const addin_name = "vbaDeveloper"
26+
Public Const TOOL_NAME = "vbaDeveloper"
2827

2928
Sub AutoInstaller()
3029

@@ -33,10 +32,10 @@ Sub AutoInstaller()
3332
End Sub
3433
Sub AutoInstaller_step0()
3534

36-
'Close the vbaDevelopper Workbook if already open and uninstall
35+
'Close the vbaDevelopper Workbook if already open and uninstall from addins
3736
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
4039
On Error GoTo 0
4140

4241
Application.OnTime Now + TimeValue("00:00:06"), "AutoInstaller_step1"
@@ -59,7 +58,7 @@ strPathOfBuild = CurrentWB.Path & "\src\vbaDeveloper.xlam\Build.bas"
5958
NewWB.VBProject.VBComponents.Import strPathOfBuild
6059

6160
'Rename the project (in the VBA) to vbaDeveloper
62-
NewWB.VBProject.Name = addin_name
61+
NewWB.VBProject.Name = TOOL_NAME
6362

6463
'Add references to the library
6564
'Microsoft Scripting Runtime
@@ -73,14 +72,14 @@ NewWB.VBProject.VBComponents.Import strPathOfBuild
7372
'In VB Editor, menu File-->Save Book1; Save as vbaDeveloper.xlam in the same directory as 'src'
7473

7574
strLocationXLAM = CurrentWB.Path
76-
NewWB.SaveAs strLocationXLAM & "\" & addin_name & ".xlam", xlOpenXMLAddIn
75+
NewWB.SaveAs strLocationXLAM & "\" & TOOL_NAME & ".xlam", xlOpenXMLAddIn
7776

7877
'Close excel. Open excel with a new workbook, then open the just saved vbaDeveloper.xlam
7978
NewWB.Close savechanges:=False
8079

8180
'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)
8483
End If
8584

8685
'Continue to step 2
@@ -91,7 +90,7 @@ End Sub
9190
Sub AutoInstaller_step2()
9291

9392
'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
9594

9695
Application.OnTime Now + TimeValue("00:00:02"), "AutoInstaller_step3"
9796

@@ -113,9 +112,9 @@ Sub AutoInstaller_step4()
113112
'Run the Workbook_Open macro from vbaDeveloper
114113
Application.Run "vbaDeveloper.xlam!Menu.createMenu"
115114

116-
Workbooks(addin_name & ".xlam").Save
115+
Workbooks(TOOL_NAME & ".xlam").Save
117116

118-
MsgBox addin_name & " was successfully installed."
117+
MsgBox TOOL_NAME & " was successfully installed."
119118

120119
End Sub
121120

@@ -140,3 +139,41 @@ Function AddinName2index(ByVal addin_name As String) As Integer
140139
'If we get to this line, it means no match was found
141140
AddinName2index = 0
142141
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

Comments
 (0)