-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdev_tools.bas
118 lines (102 loc) · 4 KB
/
dev_tools.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
Attribute VB_Name = "developer_tools"
Option Explicit
' This file is part of the Minnesota Population Center's VBA libraries project.
' For copyright and licensing information, see the NOTICE and LICENSE files
' in this project's top-level directory, and also on-line at:
' https://github.com/mnpopcenter/vba-libs
' Module dependencies:
' bootstrap
' conf
' loader
' toolkit
' Full path to the production version of this add-in
Private ProductionAddInPath As String
' Names of macros to run before and after building the production version
' (default = "", which is a no-op).
Public PreBuildMacro As String ' Sub()
Public PostBuildMacro As String ' Function(build_message As String) As String
' returns an updated build message or ""
' if an error occurred and was displayed
' to the developer.
Public Sub ExportVbaCode()
Dim message As String
message = "Exported the VBA code into these files:" & vbCr
Dim component
For Each component In ThisWorkbook.VBProject.VBComponents
Dim module_path As String
If component.Name = "ThisWorkbook" Or component.Name = "Sheet1" Then
module_path = PathInThisWorkbookDir(component.Name & ".cls")
Else
module_path = loader.ModulePaths(component.Name)
End If
component.Export module_path
Dim file_name As String
file_name = Replace(module_path, PathInThisWorkbookDir(""), "")
message = message & vbCr & _
" " & component.Name & " --> " & file_name
Next component
MsgBox message & vbCr & _
vbCr & _
"The files are located in this directory:" & vbCr & _
vbCr & _
ThisWorkbook.Path, vbOKOnly, "Exported VBA Code"
End Sub
Public Sub BuildProductionVersion()
Dim prod_add_in_name As String
prod_add_in_name = Replace(ThisWorkbook.Name, "_DEV", "_PROD")
ProductionAddInPath = PathInThisWorkbookDir(prod_add_in_name)
Dim message As String
Dim window_title As String
If FileExists(ProductionAddInPath) Then
message = "The add-in """ & prod_add_in_name & """ already exists in" & _
" the folder:" & _
vbCr & vbCr & _
ThisWorkbook.Path & _
vbCr & vbCr & _
"Do you want to rebuild it?"
Dim Answer As Integer
Answer = MsgBox(message, vbYesNo, "Rebuild the Add-in?")
If Answer = vbNo Then
Exit Sub
End If
Kill ProductionAddInPath
window_title = "Rebuilt the Production Add-in"
Else
window_title = "Built the Production Add-in"
End If
If PreBuildMacro <> "" Then Application.Run PreBuildMacro
MakeProductionAddIn
message = "Created the add-in """ & prod_add_in_name & """ in the folder:" & _
vbCr & vbCr & _
ThisWorkbook.Path
If PostBuildMacro <> "" Then
message = Application.Run(PostBuildMacro, message)
If message = "" Then
' Error occurred and the developer was notified, so just exit
Exit Sub
End If
End If
MsgBox message, vbOKOnly, window_title
End Sub
Private Sub MakeProductionAddIn()
toolkit.StoreBuildDateTime Now()
' Set the add-in's Title and Comments (description) for the production
' version
Dim titleDev As String
titleDev = ThisWorkbook.Title
Dim commentsDev As String
commentsDev = ThisWorkbook.Comments
bootstrap.AllowToolkitSave = True
With ThisWorkbook
.Title = Replace(titleDev, " (dev)", "")
.Comments = Replace(commentsDev, "development version", _
"version " & conf.VERSION_STR)
.SaveAs ProductionAddInPath, xlOpenXMLAddIn
End With
bootstrap.AllowToolkitSave = False
' Restore the development version of Title and Comments
With ThisWorkbook
.Title = titleDev
.Comments = commentsDev
End With
End Sub