Source control of Excel VBA code modules
I'd like to be able to source control my Excel spreadsheet's VBA modules (currently using Excel 2003 SP3) so that I can share and manage the code used by a bunch of different spreadsheets - and therefore I'd like to re-load them from files when the spreadsheet is opened.
I've got a module called Loader.bas, that I use to do most of the donkey work (loading and unloading any other modules that are required) - and I'd like to be able to load it up from a file as soon as the spreadsheet is opened.
I've attached the following code to the Workbook_Open event (in the ThisWorkbook class).
Private Sub Workbook_Open()
Call RemoveLoader
Call LoadLoader
End Sub
Where RemoveLoader (also within the ThisWorkbook class) contains the following code:
Private Sub RemoveLoader()
Dim y As Integer
Dim OldModules, NumModules As Integer
Dim CompName As String
With ThisWorkbook.VBProject
NumModules = ThisWorkbook.VBProject.VBComponents.Count
y = 1
While y <= NumModules
If .VBComponents.Item(y).Type = 1 Then
CompName = .VBComponents.Item(y).Name
If VBA.Strings.InStr(CompName, "Loader") > 0 Then
OldModules = ThisWorkbook.VBProject.VBComponents.Count
.VBComponents.Remove .VBComponents(CompName)
NumModules = ThisWorkbook.VBProject.VBComponents.Count
If OldModules - NumModules = 1 Then
y = 1
Else
MsgBox ("Failed to remove " & CompName & " module from VBA project")
End If
End If
End If
y = y + 1
Wend
End With
End Sub
Which is probably a bit overcomplicated and slightly crude - but I'm trying everything I can find to get it to load the external module!
Often, when I open the spreadsheet, the RemoveLoader function finds that there's a "Loader1" module already included in the VBA project that it is unable to remove, and it also fails to load the new Loader module from the file.
Any ideas if what I'm trying to do is possible? Excel seems very fond of appending a 1 to these module names - either when loading or removing (I'm not sure which).
excel vba excel-vba
add a comment |
I'd like to be able to source control my Excel spreadsheet's VBA modules (currently using Excel 2003 SP3) so that I can share and manage the code used by a bunch of different spreadsheets - and therefore I'd like to re-load them from files when the spreadsheet is opened.
I've got a module called Loader.bas, that I use to do most of the donkey work (loading and unloading any other modules that are required) - and I'd like to be able to load it up from a file as soon as the spreadsheet is opened.
I've attached the following code to the Workbook_Open event (in the ThisWorkbook class).
Private Sub Workbook_Open()
Call RemoveLoader
Call LoadLoader
End Sub
Where RemoveLoader (also within the ThisWorkbook class) contains the following code:
Private Sub RemoveLoader()
Dim y As Integer
Dim OldModules, NumModules As Integer
Dim CompName As String
With ThisWorkbook.VBProject
NumModules = ThisWorkbook.VBProject.VBComponents.Count
y = 1
While y <= NumModules
If .VBComponents.Item(y).Type = 1 Then
CompName = .VBComponents.Item(y).Name
If VBA.Strings.InStr(CompName, "Loader") > 0 Then
OldModules = ThisWorkbook.VBProject.VBComponents.Count
.VBComponents.Remove .VBComponents(CompName)
NumModules = ThisWorkbook.VBProject.VBComponents.Count
If OldModules - NumModules = 1 Then
y = 1
Else
MsgBox ("Failed to remove " & CompName & " module from VBA project")
End If
End If
End If
y = y + 1
Wend
End With
End Sub
Which is probably a bit overcomplicated and slightly crude - but I'm trying everything I can find to get it to load the external module!
Often, when I open the spreadsheet, the RemoveLoader function finds that there's a "Loader1" module already included in the VBA project that it is unable to remove, and it also fails to load the new Loader module from the file.
Any ideas if what I'm trying to do is possible? Excel seems very fond of appending a 1 to these module names - either when loading or removing (I'm not sure which).
excel vba excel-vba
I forgot to add that I did some thinking and came up with this: grumpyop.wordpress.com/2009/04/20/… Note that there's also something called VBAMaven mentioned in the comments that looks like some external service that might help.
– Mike Woodhouse
May 19 '09 at 19:13
add a comment |
I'd like to be able to source control my Excel spreadsheet's VBA modules (currently using Excel 2003 SP3) so that I can share and manage the code used by a bunch of different spreadsheets - and therefore I'd like to re-load them from files when the spreadsheet is opened.
I've got a module called Loader.bas, that I use to do most of the donkey work (loading and unloading any other modules that are required) - and I'd like to be able to load it up from a file as soon as the spreadsheet is opened.
I've attached the following code to the Workbook_Open event (in the ThisWorkbook class).
Private Sub Workbook_Open()
Call RemoveLoader
Call LoadLoader
End Sub
Where RemoveLoader (also within the ThisWorkbook class) contains the following code:
Private Sub RemoveLoader()
Dim y As Integer
Dim OldModules, NumModules As Integer
Dim CompName As String
With ThisWorkbook.VBProject
NumModules = ThisWorkbook.VBProject.VBComponents.Count
y = 1
While y <= NumModules
If .VBComponents.Item(y).Type = 1 Then
CompName = .VBComponents.Item(y).Name
If VBA.Strings.InStr(CompName, "Loader") > 0 Then
OldModules = ThisWorkbook.VBProject.VBComponents.Count
.VBComponents.Remove .VBComponents(CompName)
NumModules = ThisWorkbook.VBProject.VBComponents.Count
If OldModules - NumModules = 1 Then
y = 1
Else
MsgBox ("Failed to remove " & CompName & " module from VBA project")
End If
End If
End If
y = y + 1
Wend
End With
End Sub
Which is probably a bit overcomplicated and slightly crude - but I'm trying everything I can find to get it to load the external module!
Often, when I open the spreadsheet, the RemoveLoader function finds that there's a "Loader1" module already included in the VBA project that it is unable to remove, and it also fails to load the new Loader module from the file.
Any ideas if what I'm trying to do is possible? Excel seems very fond of appending a 1 to these module names - either when loading or removing (I'm not sure which).
excel vba excel-vba
I'd like to be able to source control my Excel spreadsheet's VBA modules (currently using Excel 2003 SP3) so that I can share and manage the code used by a bunch of different spreadsheets - and therefore I'd like to re-load them from files when the spreadsheet is opened.
I've got a module called Loader.bas, that I use to do most of the donkey work (loading and unloading any other modules that are required) - and I'd like to be able to load it up from a file as soon as the spreadsheet is opened.
I've attached the following code to the Workbook_Open event (in the ThisWorkbook class).
Private Sub Workbook_Open()
Call RemoveLoader
Call LoadLoader
End Sub
Where RemoveLoader (also within the ThisWorkbook class) contains the following code:
Private Sub RemoveLoader()
Dim y As Integer
Dim OldModules, NumModules As Integer
Dim CompName As String
With ThisWorkbook.VBProject
NumModules = ThisWorkbook.VBProject.VBComponents.Count
y = 1
While y <= NumModules
If .VBComponents.Item(y).Type = 1 Then
CompName = .VBComponents.Item(y).Name
If VBA.Strings.InStr(CompName, "Loader") > 0 Then
OldModules = ThisWorkbook.VBProject.VBComponents.Count
.VBComponents.Remove .VBComponents(CompName)
NumModules = ThisWorkbook.VBProject.VBComponents.Count
If OldModules - NumModules = 1 Then
y = 1
Else
MsgBox ("Failed to remove " & CompName & " module from VBA project")
End If
End If
End If
y = y + 1
Wend
End With
End Sub
Which is probably a bit overcomplicated and slightly crude - but I'm trying everything I can find to get it to load the external module!
Often, when I open the spreadsheet, the RemoveLoader function finds that there's a "Loader1" module already included in the VBA project that it is unable to remove, and it also fails to load the new Loader module from the file.
Any ideas if what I'm trying to do is possible? Excel seems very fond of appending a 1 to these module names - either when loading or removing (I'm not sure which).
excel vba excel-vba
excel vba excel-vba
edited Oct 6 '09 at 12:01
Jon Mills
asked Apr 1 '09 at 9:28
Jon MillsJon Mills
1,02421024
1,02421024
I forgot to add that I did some thinking and came up with this: grumpyop.wordpress.com/2009/04/20/… Note that there's also something called VBAMaven mentioned in the comments that looks like some external service that might help.
– Mike Woodhouse
May 19 '09 at 19:13
add a comment |
I forgot to add that I did some thinking and came up with this: grumpyop.wordpress.com/2009/04/20/… Note that there's also something called VBAMaven mentioned in the comments that looks like some external service that might help.
– Mike Woodhouse
May 19 '09 at 19:13
I forgot to add that I did some thinking and came up with this: grumpyop.wordpress.com/2009/04/20/… Note that there's also something called VBAMaven mentioned in the comments that looks like some external service that might help.
– Mike Woodhouse
May 19 '09 at 19:13
I forgot to add that I did some thinking and came up with this: grumpyop.wordpress.com/2009/04/20/… Note that there's also something called VBAMaven mentioned in the comments that looks like some external service that might help.
– Mike Woodhouse
May 19 '09 at 19:13
add a comment |
5 Answers
5
active
oldest
votes
Look at the VBAMaven page. I have a homegrown solution that uses the same concepts. I have a common library with a bunch of source code, an ant build and an 'import' VB script. Ant controls the build, which takes a blank excel file and pushes the needed code into it. @Mike is absolutely correct - any duplicate module definitions will automatically have a number appended to the module name. Also, class modules (as in Sheet and ThisWorkbook) classes require special treatment. You can't create those modules, you have to read the input file and write the buffer into the appropriate module. This is the VB script I currently use to do this. The section containing @ delimited text (i.e. @build file@) are placeholders - the ant build replaces these tags with meaningful content. It's not perfect, but works for me.
''
' Imports VB Basic module and class files from the src folder
' into the excel file stored in the bin folder.
'
Option Explicit
Dim pFileSystem, pFolder, pPath
Dim pShell
Dim pApp, book
Dim pFileName
pFileName = "@build file@"
Set pFileSystem = CreateObject("Scripting.FileSystemObject")
Set pShell = CreateObject("WScript.Shell")
pPath = pShell.CurrentDirectory
If IsExcelFile (pFileName) Then
Set pApp = WScript.CreateObject ("Excel.Application")
pApp.Visible = False
Set book = pApp.Workbooks.Open(pPath & "build" & pFileName)
Else
Set pApp = WScript.CreateObject ("Word.Application")
pApp.Visible = False
Set book = pApp.Documents.Open(pPath & "build" & pFileName)
End If
'Include root source folder code if no args set
If Wscript.Arguments.Count = 0 Then
Set pFolder = pFileSystem.GetFolder(pPath & "src")
ImportFiles pFolder, book
'
' Get selected modules from the Common Library, if any
@common path@@common file@
Else
'Add code from subdirectories of src . . .
If Wscript.Arguments(0) <> "" Then
Set pFolder = pFileSystem.GetFolder(pPath & "src" & Wscript.Arguments(0))
ImportFiles pFolder, book
End If
End If
Set pFolder = Nothing
Set pFileSystem = Nothing
Set pShell = Nothing
If IsExcelFile (pFileName) Then
pApp.ActiveWorkbook.Save
Else
pApp.ActiveDocument.Save
End If
pApp.Quit
Set book = Nothing
Set pApp = Nothing
'' Loops through all the .bas or .cls files in srcFolder
' and calls InsertVBComponent to insert it into the workbook wb.
'
Sub ImportFiles(ByVal srcFolder, ByVal obj)
Dim fileCollection, pFile
Set fileCollection = srcFolder.Files
For Each pFile in fileCollection
If Right(pFile, 3) = "bas _
Or Right(pFile, 3) = "cls _
Or Right(pFile, 3) = "frm Then
InsertVBComponent obj, pFile
End If
Next
Set fileCollection = Nothing
End Sub
'' Inserts the contents of CompFileName as a new component in
' a Workbook or Document object.
'
' If a class file begins with "Sheet", then the code is
' copied into the appropriate code module 1 painful line at a time.
'
' CompFileName must be a valid VBA component (class or module)
Sub InsertVBComponent(ByVal obj, ByVal CompFileName)
Dim t, mName
t = Split(CompFileName, "")
mName = Split(t(UBound(t)), ".")
If IsSheetCodeModule(mName(0), CompFileName) = True Then
ImportCodeModule obj.VBProject.VBComponents(mName(0)).CodeModule, _
CompFileName
Else
If Not obj Is Nothing Then
obj.VBProject.VBComponents.Import CompFileName
Else
WScript.Echo "Failed to import " & CompFileName
End If
End If
End Sub
''
' Imports the code in the file fName into the workbook object
' referenced by mName.
' @param target destination CodeModule object in the excel file
' @param fName file system file containing code to be imported
Sub ImportCodeModule (ByVal target, ByVal fName)
Dim shtModule, code, buf
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set buf = fso.OpenTextFile(fName, ForReading, False, TristateUseDefault)
buf.SkipLine
code = buf.ReadAll
target.InsertLines 1, code
Set fso = Nothing
End Sub
''
' Returns true if the code module in the file fName
' appears to be a code module for a worksheet.
Function IsSheetCodeModule (ByVal mName, ByVal fName)
IsSheetCodeModule = False
If mName = "ThisWorkbook" Then
IsSheetCodeModule = False
ElseIf Left(mName, 5) = "Sheet" And _
IsNumeric(Mid (mName, 6, 1)) And _
Right(fName, 3) = "cls Then
IsSheetCodeModule = True
End If
End Function
''
' Returns true if fName has a xls file extension
Function IsExcelFile (ByVal fName)
If Right(fName, 3) = "xls" Then
IsExcelFile = True
Else
IsExcelFile = False
End If
End Function
Thanks for this. I've looked at your script, and vbaMaven and it looks like both methods create a brand new spreadsheet and copy the macros into them. Is that correct? I was hoping to find a method to load the macros into the spreadsheet when the spreadsheet is opened - but I've completely failed to get that to work. Perhaps I'm trying to do something that can't be done with Excel. I'm now starting to look at replacing my macros with an external script which accesses Excel via COM - so at least I can keep the script under version control.
– Jon Mills
Sep 22 '09 at 8:25
Yes, the basic idea is a 'blank' spread sheet is copied and the code is copied into it. If I had known about vbaMaven before I started, I just might have gone with it... The reason I chose to go this route is so that every line of code can be under source control. If you have code in a workbook that loads other code, then your code loading module isn't under the same level of control as everything else - it's wrpped inside an excel file.
– DaveParillo
Sep 26 '09 at 1:35
Also, you have to be very careful modifying event code on Auto_Open or Workbook_Open events. Trying to edit the ThisWorkbook object from within the Auto_Open function is a fast path to crashing excel.
– DaveParillo
Sep 26 '09 at 1:38
Thanks Dave. In summary then, it seems that its definitely possible to automate the creation of workbooks which include externally defined macros (either using your script above, or vbaMaven) and then open the workbooks in Excel - but it doesn't seem to be possible to pull the macros into Excel at "run-time".
– Jon Mills
Oct 6 '09 at 11:56
Yes you can if you are OK with having code exist within your configuration managed template. Chip Pearson has a good overview of how to add modules dynamically: cpearson.com/Excel/vbe.aspx. My preference is to treat the excel workbook no different from a binary executable, so I use the "compile" process outlined in my answer. My top priority was to have absolutely no code in my excel templates and have all source code under version control. Hope this helps clarify a bit.
– DaveParillo
Oct 6 '09 at 15:05
add a comment |
There is an excellent solution to the vba version control problem here: https://github.com/hilkoc/vbaDeveloper
The nice part about this is that it exports your code automatically, as soon as you save your workbook. Also, when you open a workbook, it imports the code.
You don't need to run any build scripts or maven commands and you don't need to make any changes to your workbooks. It works for all.
It has also solved the import problem where modules such as ModName are being imported as ModName1 into a duplicate module. The importing works as it should, even when doing it multiple times.
As a bonus, it comes with a simple code formatter, that allows you to format your vba code as you write it within the VBA Editor.
1
I just went through the whole build-process, and there are two issues, I would like to ask if you have figured out: 1. The Add-Ins ribbon isn't showing the vbaDeveloper menu, unless I run the refreshMenu() method provided in the Menu module 2. Exporting the code doesn't happen automatically, instead I have to trigger the action manually
– Marcus Mangelsdorf
Jul 1 '15 at 12:40
3
1 The menu will be created by the workbook_open event. For that to work build save and close the add-in. Then after opening it again the workbook_open event will be triggered, unless you manually disabled that with : Application.EnableEvents = False 2 The automatic import/export is disabled by default: github.com/hilkoc/vbaDeveloper/issues/8
– CodeKid
Jul 1 '15 at 15:10
add a comment |
I've been working on exactly this for months. I think I figured it out.
If the VB Project is trying to remove a module containing something in the call stack, it delays the removal until the call stack pops the module being replaced.
To avoid a module being in the call stack, launch your code with Application.OnTime
Private Sub Workbook_Open()
'WAS: module_library (1)
Application.OnTime (Now + TimeValue("00:00:01")), "load_library_kicker_firstiter"
End Sub
If you are self-healing your code like I am, you'll also have to launch your code that overwrites the 'calling' code with that same strategy.
I did not perform extensive testing yet, I am in total celebration mode, but this gets me extremely close to straightforward 99.9% self-healing code within a standalone .xls file without any other tricks
1
THANK YOU. This was my exact problem nearly 4 years later.
– enderland
Nov 11 '13 at 19:30
add a comment |
Usually the "Loader1" thing happens when Excel is asked to import a module and a module already exists with the same name. So if you import "Loader", then load it again and you'll get "Loader1". This would be because Excel doesn't know (or maybe just doesn't care) if it's really the same thing or a new chunk of functionality that just happens have the same module name, so it imports it anyway.
I can't think of a perfect solution, but I think I'd be inclined to try putting the load/unload logic in an add-in - that Workbook_Open thing looks a little vulnerable and having it in all workbooks is going to be a huge pain if the code ever needs to change (never say never). The XLA logic might be more complex (trickier to trap the necessary events, for one thing) but at least it'll only exist in one place.
Thanks for the answer Mike. You might be correct, an AddIn might be the only way of doing it. I was trying to avoid the AddIn solution, because I'd like to store the macros in SubVersion - so I'd prefer to store them as text files so I can merge and diff easily - rather than a binary XLA file.
– Jon Mills
Apr 3 '09 at 7:57
Maybe use a tiny addin to load the modules?
– Mike Woodhouse
Apr 3 '09 at 10:05
I'm not sure how using an AddIn is going to help in this situation. To load non-binary VBA modules into excel, I'm still going to have to run some sort of code when the Workbook is opened - and I don't think that keeping the Loader code in an AddIn will change the essence of the problem.
– Jon Mills
May 19 '09 at 14:27
Apparently the Addin approach does work. See my answer below. Their addin keeps all the import export logic in once place. It also hooks into the 'open' and 'save' events for excel, such that you don't need to write workbook_open() subs in all your workbooks.
– CodeKid
Sep 22 '14 at 23:58
add a comment |
Can't leave comment to comment
There is an excellent solution to the vba version control problem
here: https://github.com/hilkoc/vbaDeveloper
About saving custom VBAProjects using this XLAM.
Try this in Build.bas:
'===============
Public Sub testImport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.importVbaCode vbaProject
End Sub
'===============
Public Sub testExport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.exportVbaCode vbaProject
End Sub
'===============
This will export/import Active VBA Project.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f704759%2fsource-control-of-excel-vba-code-modules%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Look at the VBAMaven page. I have a homegrown solution that uses the same concepts. I have a common library with a bunch of source code, an ant build and an 'import' VB script. Ant controls the build, which takes a blank excel file and pushes the needed code into it. @Mike is absolutely correct - any duplicate module definitions will automatically have a number appended to the module name. Also, class modules (as in Sheet and ThisWorkbook) classes require special treatment. You can't create those modules, you have to read the input file and write the buffer into the appropriate module. This is the VB script I currently use to do this. The section containing @ delimited text (i.e. @build file@) are placeholders - the ant build replaces these tags with meaningful content. It's not perfect, but works for me.
''
' Imports VB Basic module and class files from the src folder
' into the excel file stored in the bin folder.
'
Option Explicit
Dim pFileSystem, pFolder, pPath
Dim pShell
Dim pApp, book
Dim pFileName
pFileName = "@build file@"
Set pFileSystem = CreateObject("Scripting.FileSystemObject")
Set pShell = CreateObject("WScript.Shell")
pPath = pShell.CurrentDirectory
If IsExcelFile (pFileName) Then
Set pApp = WScript.CreateObject ("Excel.Application")
pApp.Visible = False
Set book = pApp.Workbooks.Open(pPath & "build" & pFileName)
Else
Set pApp = WScript.CreateObject ("Word.Application")
pApp.Visible = False
Set book = pApp.Documents.Open(pPath & "build" & pFileName)
End If
'Include root source folder code if no args set
If Wscript.Arguments.Count = 0 Then
Set pFolder = pFileSystem.GetFolder(pPath & "src")
ImportFiles pFolder, book
'
' Get selected modules from the Common Library, if any
@common path@@common file@
Else
'Add code from subdirectories of src . . .
If Wscript.Arguments(0) <> "" Then
Set pFolder = pFileSystem.GetFolder(pPath & "src" & Wscript.Arguments(0))
ImportFiles pFolder, book
End If
End If
Set pFolder = Nothing
Set pFileSystem = Nothing
Set pShell = Nothing
If IsExcelFile (pFileName) Then
pApp.ActiveWorkbook.Save
Else
pApp.ActiveDocument.Save
End If
pApp.Quit
Set book = Nothing
Set pApp = Nothing
'' Loops through all the .bas or .cls files in srcFolder
' and calls InsertVBComponent to insert it into the workbook wb.
'
Sub ImportFiles(ByVal srcFolder, ByVal obj)
Dim fileCollection, pFile
Set fileCollection = srcFolder.Files
For Each pFile in fileCollection
If Right(pFile, 3) = "bas _
Or Right(pFile, 3) = "cls _
Or Right(pFile, 3) = "frm Then
InsertVBComponent obj, pFile
End If
Next
Set fileCollection = Nothing
End Sub
'' Inserts the contents of CompFileName as a new component in
' a Workbook or Document object.
'
' If a class file begins with "Sheet", then the code is
' copied into the appropriate code module 1 painful line at a time.
'
' CompFileName must be a valid VBA component (class or module)
Sub InsertVBComponent(ByVal obj, ByVal CompFileName)
Dim t, mName
t = Split(CompFileName, "")
mName = Split(t(UBound(t)), ".")
If IsSheetCodeModule(mName(0), CompFileName) = True Then
ImportCodeModule obj.VBProject.VBComponents(mName(0)).CodeModule, _
CompFileName
Else
If Not obj Is Nothing Then
obj.VBProject.VBComponents.Import CompFileName
Else
WScript.Echo "Failed to import " & CompFileName
End If
End If
End Sub
''
' Imports the code in the file fName into the workbook object
' referenced by mName.
' @param target destination CodeModule object in the excel file
' @param fName file system file containing code to be imported
Sub ImportCodeModule (ByVal target, ByVal fName)
Dim shtModule, code, buf
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set buf = fso.OpenTextFile(fName, ForReading, False, TristateUseDefault)
buf.SkipLine
code = buf.ReadAll
target.InsertLines 1, code
Set fso = Nothing
End Sub
''
' Returns true if the code module in the file fName
' appears to be a code module for a worksheet.
Function IsSheetCodeModule (ByVal mName, ByVal fName)
IsSheetCodeModule = False
If mName = "ThisWorkbook" Then
IsSheetCodeModule = False
ElseIf Left(mName, 5) = "Sheet" And _
IsNumeric(Mid (mName, 6, 1)) And _
Right(fName, 3) = "cls Then
IsSheetCodeModule = True
End If
End Function
''
' Returns true if fName has a xls file extension
Function IsExcelFile (ByVal fName)
If Right(fName, 3) = "xls" Then
IsExcelFile = True
Else
IsExcelFile = False
End If
End Function
Thanks for this. I've looked at your script, and vbaMaven and it looks like both methods create a brand new spreadsheet and copy the macros into them. Is that correct? I was hoping to find a method to load the macros into the spreadsheet when the spreadsheet is opened - but I've completely failed to get that to work. Perhaps I'm trying to do something that can't be done with Excel. I'm now starting to look at replacing my macros with an external script which accesses Excel via COM - so at least I can keep the script under version control.
– Jon Mills
Sep 22 '09 at 8:25
Yes, the basic idea is a 'blank' spread sheet is copied and the code is copied into it. If I had known about vbaMaven before I started, I just might have gone with it... The reason I chose to go this route is so that every line of code can be under source control. If you have code in a workbook that loads other code, then your code loading module isn't under the same level of control as everything else - it's wrpped inside an excel file.
– DaveParillo
Sep 26 '09 at 1:35
Also, you have to be very careful modifying event code on Auto_Open or Workbook_Open events. Trying to edit the ThisWorkbook object from within the Auto_Open function is a fast path to crashing excel.
– DaveParillo
Sep 26 '09 at 1:38
Thanks Dave. In summary then, it seems that its definitely possible to automate the creation of workbooks which include externally defined macros (either using your script above, or vbaMaven) and then open the workbooks in Excel - but it doesn't seem to be possible to pull the macros into Excel at "run-time".
– Jon Mills
Oct 6 '09 at 11:56
Yes you can if you are OK with having code exist within your configuration managed template. Chip Pearson has a good overview of how to add modules dynamically: cpearson.com/Excel/vbe.aspx. My preference is to treat the excel workbook no different from a binary executable, so I use the "compile" process outlined in my answer. My top priority was to have absolutely no code in my excel templates and have all source code under version control. Hope this helps clarify a bit.
– DaveParillo
Oct 6 '09 at 15:05
add a comment |
Look at the VBAMaven page. I have a homegrown solution that uses the same concepts. I have a common library with a bunch of source code, an ant build and an 'import' VB script. Ant controls the build, which takes a blank excel file and pushes the needed code into it. @Mike is absolutely correct - any duplicate module definitions will automatically have a number appended to the module name. Also, class modules (as in Sheet and ThisWorkbook) classes require special treatment. You can't create those modules, you have to read the input file and write the buffer into the appropriate module. This is the VB script I currently use to do this. The section containing @ delimited text (i.e. @build file@) are placeholders - the ant build replaces these tags with meaningful content. It's not perfect, but works for me.
''
' Imports VB Basic module and class files from the src folder
' into the excel file stored in the bin folder.
'
Option Explicit
Dim pFileSystem, pFolder, pPath
Dim pShell
Dim pApp, book
Dim pFileName
pFileName = "@build file@"
Set pFileSystem = CreateObject("Scripting.FileSystemObject")
Set pShell = CreateObject("WScript.Shell")
pPath = pShell.CurrentDirectory
If IsExcelFile (pFileName) Then
Set pApp = WScript.CreateObject ("Excel.Application")
pApp.Visible = False
Set book = pApp.Workbooks.Open(pPath & "build" & pFileName)
Else
Set pApp = WScript.CreateObject ("Word.Application")
pApp.Visible = False
Set book = pApp.Documents.Open(pPath & "build" & pFileName)
End If
'Include root source folder code if no args set
If Wscript.Arguments.Count = 0 Then
Set pFolder = pFileSystem.GetFolder(pPath & "src")
ImportFiles pFolder, book
'
' Get selected modules from the Common Library, if any
@common path@@common file@
Else
'Add code from subdirectories of src . . .
If Wscript.Arguments(0) <> "" Then
Set pFolder = pFileSystem.GetFolder(pPath & "src" & Wscript.Arguments(0))
ImportFiles pFolder, book
End If
End If
Set pFolder = Nothing
Set pFileSystem = Nothing
Set pShell = Nothing
If IsExcelFile (pFileName) Then
pApp.ActiveWorkbook.Save
Else
pApp.ActiveDocument.Save
End If
pApp.Quit
Set book = Nothing
Set pApp = Nothing
'' Loops through all the .bas or .cls files in srcFolder
' and calls InsertVBComponent to insert it into the workbook wb.
'
Sub ImportFiles(ByVal srcFolder, ByVal obj)
Dim fileCollection, pFile
Set fileCollection = srcFolder.Files
For Each pFile in fileCollection
If Right(pFile, 3) = "bas _
Or Right(pFile, 3) = "cls _
Or Right(pFile, 3) = "frm Then
InsertVBComponent obj, pFile
End If
Next
Set fileCollection = Nothing
End Sub
'' Inserts the contents of CompFileName as a new component in
' a Workbook or Document object.
'
' If a class file begins with "Sheet", then the code is
' copied into the appropriate code module 1 painful line at a time.
'
' CompFileName must be a valid VBA component (class or module)
Sub InsertVBComponent(ByVal obj, ByVal CompFileName)
Dim t, mName
t = Split(CompFileName, "")
mName = Split(t(UBound(t)), ".")
If IsSheetCodeModule(mName(0), CompFileName) = True Then
ImportCodeModule obj.VBProject.VBComponents(mName(0)).CodeModule, _
CompFileName
Else
If Not obj Is Nothing Then
obj.VBProject.VBComponents.Import CompFileName
Else
WScript.Echo "Failed to import " & CompFileName
End If
End If
End Sub
''
' Imports the code in the file fName into the workbook object
' referenced by mName.
' @param target destination CodeModule object in the excel file
' @param fName file system file containing code to be imported
Sub ImportCodeModule (ByVal target, ByVal fName)
Dim shtModule, code, buf
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set buf = fso.OpenTextFile(fName, ForReading, False, TristateUseDefault)
buf.SkipLine
code = buf.ReadAll
target.InsertLines 1, code
Set fso = Nothing
End Sub
''
' Returns true if the code module in the file fName
' appears to be a code module for a worksheet.
Function IsSheetCodeModule (ByVal mName, ByVal fName)
IsSheetCodeModule = False
If mName = "ThisWorkbook" Then
IsSheetCodeModule = False
ElseIf Left(mName, 5) = "Sheet" And _
IsNumeric(Mid (mName, 6, 1)) And _
Right(fName, 3) = "cls Then
IsSheetCodeModule = True
End If
End Function
''
' Returns true if fName has a xls file extension
Function IsExcelFile (ByVal fName)
If Right(fName, 3) = "xls" Then
IsExcelFile = True
Else
IsExcelFile = False
End If
End Function
Thanks for this. I've looked at your script, and vbaMaven and it looks like both methods create a brand new spreadsheet and copy the macros into them. Is that correct? I was hoping to find a method to load the macros into the spreadsheet when the spreadsheet is opened - but I've completely failed to get that to work. Perhaps I'm trying to do something that can't be done with Excel. I'm now starting to look at replacing my macros with an external script which accesses Excel via COM - so at least I can keep the script under version control.
– Jon Mills
Sep 22 '09 at 8:25
Yes, the basic idea is a 'blank' spread sheet is copied and the code is copied into it. If I had known about vbaMaven before I started, I just might have gone with it... The reason I chose to go this route is so that every line of code can be under source control. If you have code in a workbook that loads other code, then your code loading module isn't under the same level of control as everything else - it's wrpped inside an excel file.
– DaveParillo
Sep 26 '09 at 1:35
Also, you have to be very careful modifying event code on Auto_Open or Workbook_Open events. Trying to edit the ThisWorkbook object from within the Auto_Open function is a fast path to crashing excel.
– DaveParillo
Sep 26 '09 at 1:38
Thanks Dave. In summary then, it seems that its definitely possible to automate the creation of workbooks which include externally defined macros (either using your script above, or vbaMaven) and then open the workbooks in Excel - but it doesn't seem to be possible to pull the macros into Excel at "run-time".
– Jon Mills
Oct 6 '09 at 11:56
Yes you can if you are OK with having code exist within your configuration managed template. Chip Pearson has a good overview of how to add modules dynamically: cpearson.com/Excel/vbe.aspx. My preference is to treat the excel workbook no different from a binary executable, so I use the "compile" process outlined in my answer. My top priority was to have absolutely no code in my excel templates and have all source code under version control. Hope this helps clarify a bit.
– DaveParillo
Oct 6 '09 at 15:05
add a comment |
Look at the VBAMaven page. I have a homegrown solution that uses the same concepts. I have a common library with a bunch of source code, an ant build and an 'import' VB script. Ant controls the build, which takes a blank excel file and pushes the needed code into it. @Mike is absolutely correct - any duplicate module definitions will automatically have a number appended to the module name. Also, class modules (as in Sheet and ThisWorkbook) classes require special treatment. You can't create those modules, you have to read the input file and write the buffer into the appropriate module. This is the VB script I currently use to do this. The section containing @ delimited text (i.e. @build file@) are placeholders - the ant build replaces these tags with meaningful content. It's not perfect, but works for me.
''
' Imports VB Basic module and class files from the src folder
' into the excel file stored in the bin folder.
'
Option Explicit
Dim pFileSystem, pFolder, pPath
Dim pShell
Dim pApp, book
Dim pFileName
pFileName = "@build file@"
Set pFileSystem = CreateObject("Scripting.FileSystemObject")
Set pShell = CreateObject("WScript.Shell")
pPath = pShell.CurrentDirectory
If IsExcelFile (pFileName) Then
Set pApp = WScript.CreateObject ("Excel.Application")
pApp.Visible = False
Set book = pApp.Workbooks.Open(pPath & "build" & pFileName)
Else
Set pApp = WScript.CreateObject ("Word.Application")
pApp.Visible = False
Set book = pApp.Documents.Open(pPath & "build" & pFileName)
End If
'Include root source folder code if no args set
If Wscript.Arguments.Count = 0 Then
Set pFolder = pFileSystem.GetFolder(pPath & "src")
ImportFiles pFolder, book
'
' Get selected modules from the Common Library, if any
@common path@@common file@
Else
'Add code from subdirectories of src . . .
If Wscript.Arguments(0) <> "" Then
Set pFolder = pFileSystem.GetFolder(pPath & "src" & Wscript.Arguments(0))
ImportFiles pFolder, book
End If
End If
Set pFolder = Nothing
Set pFileSystem = Nothing
Set pShell = Nothing
If IsExcelFile (pFileName) Then
pApp.ActiveWorkbook.Save
Else
pApp.ActiveDocument.Save
End If
pApp.Quit
Set book = Nothing
Set pApp = Nothing
'' Loops through all the .bas or .cls files in srcFolder
' and calls InsertVBComponent to insert it into the workbook wb.
'
Sub ImportFiles(ByVal srcFolder, ByVal obj)
Dim fileCollection, pFile
Set fileCollection = srcFolder.Files
For Each pFile in fileCollection
If Right(pFile, 3) = "bas _
Or Right(pFile, 3) = "cls _
Or Right(pFile, 3) = "frm Then
InsertVBComponent obj, pFile
End If
Next
Set fileCollection = Nothing
End Sub
'' Inserts the contents of CompFileName as a new component in
' a Workbook or Document object.
'
' If a class file begins with "Sheet", then the code is
' copied into the appropriate code module 1 painful line at a time.
'
' CompFileName must be a valid VBA component (class or module)
Sub InsertVBComponent(ByVal obj, ByVal CompFileName)
Dim t, mName
t = Split(CompFileName, "")
mName = Split(t(UBound(t)), ".")
If IsSheetCodeModule(mName(0), CompFileName) = True Then
ImportCodeModule obj.VBProject.VBComponents(mName(0)).CodeModule, _
CompFileName
Else
If Not obj Is Nothing Then
obj.VBProject.VBComponents.Import CompFileName
Else
WScript.Echo "Failed to import " & CompFileName
End If
End If
End Sub
''
' Imports the code in the file fName into the workbook object
' referenced by mName.
' @param target destination CodeModule object in the excel file
' @param fName file system file containing code to be imported
Sub ImportCodeModule (ByVal target, ByVal fName)
Dim shtModule, code, buf
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set buf = fso.OpenTextFile(fName, ForReading, False, TristateUseDefault)
buf.SkipLine
code = buf.ReadAll
target.InsertLines 1, code
Set fso = Nothing
End Sub
''
' Returns true if the code module in the file fName
' appears to be a code module for a worksheet.
Function IsSheetCodeModule (ByVal mName, ByVal fName)
IsSheetCodeModule = False
If mName = "ThisWorkbook" Then
IsSheetCodeModule = False
ElseIf Left(mName, 5) = "Sheet" And _
IsNumeric(Mid (mName, 6, 1)) And _
Right(fName, 3) = "cls Then
IsSheetCodeModule = True
End If
End Function
''
' Returns true if fName has a xls file extension
Function IsExcelFile (ByVal fName)
If Right(fName, 3) = "xls" Then
IsExcelFile = True
Else
IsExcelFile = False
End If
End Function
Look at the VBAMaven page. I have a homegrown solution that uses the same concepts. I have a common library with a bunch of source code, an ant build and an 'import' VB script. Ant controls the build, which takes a blank excel file and pushes the needed code into it. @Mike is absolutely correct - any duplicate module definitions will automatically have a number appended to the module name. Also, class modules (as in Sheet and ThisWorkbook) classes require special treatment. You can't create those modules, you have to read the input file and write the buffer into the appropriate module. This is the VB script I currently use to do this. The section containing @ delimited text (i.e. @build file@) are placeholders - the ant build replaces these tags with meaningful content. It's not perfect, but works for me.
''
' Imports VB Basic module and class files from the src folder
' into the excel file stored in the bin folder.
'
Option Explicit
Dim pFileSystem, pFolder, pPath
Dim pShell
Dim pApp, book
Dim pFileName
pFileName = "@build file@"
Set pFileSystem = CreateObject("Scripting.FileSystemObject")
Set pShell = CreateObject("WScript.Shell")
pPath = pShell.CurrentDirectory
If IsExcelFile (pFileName) Then
Set pApp = WScript.CreateObject ("Excel.Application")
pApp.Visible = False
Set book = pApp.Workbooks.Open(pPath & "build" & pFileName)
Else
Set pApp = WScript.CreateObject ("Word.Application")
pApp.Visible = False
Set book = pApp.Documents.Open(pPath & "build" & pFileName)
End If
'Include root source folder code if no args set
If Wscript.Arguments.Count = 0 Then
Set pFolder = pFileSystem.GetFolder(pPath & "src")
ImportFiles pFolder, book
'
' Get selected modules from the Common Library, if any
@common path@@common file@
Else
'Add code from subdirectories of src . . .
If Wscript.Arguments(0) <> "" Then
Set pFolder = pFileSystem.GetFolder(pPath & "src" & Wscript.Arguments(0))
ImportFiles pFolder, book
End If
End If
Set pFolder = Nothing
Set pFileSystem = Nothing
Set pShell = Nothing
If IsExcelFile (pFileName) Then
pApp.ActiveWorkbook.Save
Else
pApp.ActiveDocument.Save
End If
pApp.Quit
Set book = Nothing
Set pApp = Nothing
'' Loops through all the .bas or .cls files in srcFolder
' and calls InsertVBComponent to insert it into the workbook wb.
'
Sub ImportFiles(ByVal srcFolder, ByVal obj)
Dim fileCollection, pFile
Set fileCollection = srcFolder.Files
For Each pFile in fileCollection
If Right(pFile, 3) = "bas _
Or Right(pFile, 3) = "cls _
Or Right(pFile, 3) = "frm Then
InsertVBComponent obj, pFile
End If
Next
Set fileCollection = Nothing
End Sub
'' Inserts the contents of CompFileName as a new component in
' a Workbook or Document object.
'
' If a class file begins with "Sheet", then the code is
' copied into the appropriate code module 1 painful line at a time.
'
' CompFileName must be a valid VBA component (class or module)
Sub InsertVBComponent(ByVal obj, ByVal CompFileName)
Dim t, mName
t = Split(CompFileName, "")
mName = Split(t(UBound(t)), ".")
If IsSheetCodeModule(mName(0), CompFileName) = True Then
ImportCodeModule obj.VBProject.VBComponents(mName(0)).CodeModule, _
CompFileName
Else
If Not obj Is Nothing Then
obj.VBProject.VBComponents.Import CompFileName
Else
WScript.Echo "Failed to import " & CompFileName
End If
End If
End Sub
''
' Imports the code in the file fName into the workbook object
' referenced by mName.
' @param target destination CodeModule object in the excel file
' @param fName file system file containing code to be imported
Sub ImportCodeModule (ByVal target, ByVal fName)
Dim shtModule, code, buf
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set buf = fso.OpenTextFile(fName, ForReading, False, TristateUseDefault)
buf.SkipLine
code = buf.ReadAll
target.InsertLines 1, code
Set fso = Nothing
End Sub
''
' Returns true if the code module in the file fName
' appears to be a code module for a worksheet.
Function IsSheetCodeModule (ByVal mName, ByVal fName)
IsSheetCodeModule = False
If mName = "ThisWorkbook" Then
IsSheetCodeModule = False
ElseIf Left(mName, 5) = "Sheet" And _
IsNumeric(Mid (mName, 6, 1)) And _
Right(fName, 3) = "cls Then
IsSheetCodeModule = True
End If
End Function
''
' Returns true if fName has a xls file extension
Function IsExcelFile (ByVal fName)
If Right(fName, 3) = "xls" Then
IsExcelFile = True
Else
IsExcelFile = False
End If
End Function
answered Sep 9 '09 at 21:48
DaveParilloDaveParillo
2,1271719
2,1271719
Thanks for this. I've looked at your script, and vbaMaven and it looks like both methods create a brand new spreadsheet and copy the macros into them. Is that correct? I was hoping to find a method to load the macros into the spreadsheet when the spreadsheet is opened - but I've completely failed to get that to work. Perhaps I'm trying to do something that can't be done with Excel. I'm now starting to look at replacing my macros with an external script which accesses Excel via COM - so at least I can keep the script under version control.
– Jon Mills
Sep 22 '09 at 8:25
Yes, the basic idea is a 'blank' spread sheet is copied and the code is copied into it. If I had known about vbaMaven before I started, I just might have gone with it... The reason I chose to go this route is so that every line of code can be under source control. If you have code in a workbook that loads other code, then your code loading module isn't under the same level of control as everything else - it's wrpped inside an excel file.
– DaveParillo
Sep 26 '09 at 1:35
Also, you have to be very careful modifying event code on Auto_Open or Workbook_Open events. Trying to edit the ThisWorkbook object from within the Auto_Open function is a fast path to crashing excel.
– DaveParillo
Sep 26 '09 at 1:38
Thanks Dave. In summary then, it seems that its definitely possible to automate the creation of workbooks which include externally defined macros (either using your script above, or vbaMaven) and then open the workbooks in Excel - but it doesn't seem to be possible to pull the macros into Excel at "run-time".
– Jon Mills
Oct 6 '09 at 11:56
Yes you can if you are OK with having code exist within your configuration managed template. Chip Pearson has a good overview of how to add modules dynamically: cpearson.com/Excel/vbe.aspx. My preference is to treat the excel workbook no different from a binary executable, so I use the "compile" process outlined in my answer. My top priority was to have absolutely no code in my excel templates and have all source code under version control. Hope this helps clarify a bit.
– DaveParillo
Oct 6 '09 at 15:05
add a comment |
Thanks for this. I've looked at your script, and vbaMaven and it looks like both methods create a brand new spreadsheet and copy the macros into them. Is that correct? I was hoping to find a method to load the macros into the spreadsheet when the spreadsheet is opened - but I've completely failed to get that to work. Perhaps I'm trying to do something that can't be done with Excel. I'm now starting to look at replacing my macros with an external script which accesses Excel via COM - so at least I can keep the script under version control.
– Jon Mills
Sep 22 '09 at 8:25
Yes, the basic idea is a 'blank' spread sheet is copied and the code is copied into it. If I had known about vbaMaven before I started, I just might have gone with it... The reason I chose to go this route is so that every line of code can be under source control. If you have code in a workbook that loads other code, then your code loading module isn't under the same level of control as everything else - it's wrpped inside an excel file.
– DaveParillo
Sep 26 '09 at 1:35
Also, you have to be very careful modifying event code on Auto_Open or Workbook_Open events. Trying to edit the ThisWorkbook object from within the Auto_Open function is a fast path to crashing excel.
– DaveParillo
Sep 26 '09 at 1:38
Thanks Dave. In summary then, it seems that its definitely possible to automate the creation of workbooks which include externally defined macros (either using your script above, or vbaMaven) and then open the workbooks in Excel - but it doesn't seem to be possible to pull the macros into Excel at "run-time".
– Jon Mills
Oct 6 '09 at 11:56
Yes you can if you are OK with having code exist within your configuration managed template. Chip Pearson has a good overview of how to add modules dynamically: cpearson.com/Excel/vbe.aspx. My preference is to treat the excel workbook no different from a binary executable, so I use the "compile" process outlined in my answer. My top priority was to have absolutely no code in my excel templates and have all source code under version control. Hope this helps clarify a bit.
– DaveParillo
Oct 6 '09 at 15:05
Thanks for this. I've looked at your script, and vbaMaven and it looks like both methods create a brand new spreadsheet and copy the macros into them. Is that correct? I was hoping to find a method to load the macros into the spreadsheet when the spreadsheet is opened - but I've completely failed to get that to work. Perhaps I'm trying to do something that can't be done with Excel. I'm now starting to look at replacing my macros with an external script which accesses Excel via COM - so at least I can keep the script under version control.
– Jon Mills
Sep 22 '09 at 8:25
Thanks for this. I've looked at your script, and vbaMaven and it looks like both methods create a brand new spreadsheet and copy the macros into them. Is that correct? I was hoping to find a method to load the macros into the spreadsheet when the spreadsheet is opened - but I've completely failed to get that to work. Perhaps I'm trying to do something that can't be done with Excel. I'm now starting to look at replacing my macros with an external script which accesses Excel via COM - so at least I can keep the script under version control.
– Jon Mills
Sep 22 '09 at 8:25
Yes, the basic idea is a 'blank' spread sheet is copied and the code is copied into it. If I had known about vbaMaven before I started, I just might have gone with it... The reason I chose to go this route is so that every line of code can be under source control. If you have code in a workbook that loads other code, then your code loading module isn't under the same level of control as everything else - it's wrpped inside an excel file.
– DaveParillo
Sep 26 '09 at 1:35
Yes, the basic idea is a 'blank' spread sheet is copied and the code is copied into it. If I had known about vbaMaven before I started, I just might have gone with it... The reason I chose to go this route is so that every line of code can be under source control. If you have code in a workbook that loads other code, then your code loading module isn't under the same level of control as everything else - it's wrpped inside an excel file.
– DaveParillo
Sep 26 '09 at 1:35
Also, you have to be very careful modifying event code on Auto_Open or Workbook_Open events. Trying to edit the ThisWorkbook object from within the Auto_Open function is a fast path to crashing excel.
– DaveParillo
Sep 26 '09 at 1:38
Also, you have to be very careful modifying event code on Auto_Open or Workbook_Open events. Trying to edit the ThisWorkbook object from within the Auto_Open function is a fast path to crashing excel.
– DaveParillo
Sep 26 '09 at 1:38
Thanks Dave. In summary then, it seems that its definitely possible to automate the creation of workbooks which include externally defined macros (either using your script above, or vbaMaven) and then open the workbooks in Excel - but it doesn't seem to be possible to pull the macros into Excel at "run-time".
– Jon Mills
Oct 6 '09 at 11:56
Thanks Dave. In summary then, it seems that its definitely possible to automate the creation of workbooks which include externally defined macros (either using your script above, or vbaMaven) and then open the workbooks in Excel - but it doesn't seem to be possible to pull the macros into Excel at "run-time".
– Jon Mills
Oct 6 '09 at 11:56
Yes you can if you are OK with having code exist within your configuration managed template. Chip Pearson has a good overview of how to add modules dynamically: cpearson.com/Excel/vbe.aspx. My preference is to treat the excel workbook no different from a binary executable, so I use the "compile" process outlined in my answer. My top priority was to have absolutely no code in my excel templates and have all source code under version control. Hope this helps clarify a bit.
– DaveParillo
Oct 6 '09 at 15:05
Yes you can if you are OK with having code exist within your configuration managed template. Chip Pearson has a good overview of how to add modules dynamically: cpearson.com/Excel/vbe.aspx. My preference is to treat the excel workbook no different from a binary executable, so I use the "compile" process outlined in my answer. My top priority was to have absolutely no code in my excel templates and have all source code under version control. Hope this helps clarify a bit.
– DaveParillo
Oct 6 '09 at 15:05
add a comment |
There is an excellent solution to the vba version control problem here: https://github.com/hilkoc/vbaDeveloper
The nice part about this is that it exports your code automatically, as soon as you save your workbook. Also, when you open a workbook, it imports the code.
You don't need to run any build scripts or maven commands and you don't need to make any changes to your workbooks. It works for all.
It has also solved the import problem where modules such as ModName are being imported as ModName1 into a duplicate module. The importing works as it should, even when doing it multiple times.
As a bonus, it comes with a simple code formatter, that allows you to format your vba code as you write it within the VBA Editor.
1
I just went through the whole build-process, and there are two issues, I would like to ask if you have figured out: 1. The Add-Ins ribbon isn't showing the vbaDeveloper menu, unless I run the refreshMenu() method provided in the Menu module 2. Exporting the code doesn't happen automatically, instead I have to trigger the action manually
– Marcus Mangelsdorf
Jul 1 '15 at 12:40
3
1 The menu will be created by the workbook_open event. For that to work build save and close the add-in. Then after opening it again the workbook_open event will be triggered, unless you manually disabled that with : Application.EnableEvents = False 2 The automatic import/export is disabled by default: github.com/hilkoc/vbaDeveloper/issues/8
– CodeKid
Jul 1 '15 at 15:10
add a comment |
There is an excellent solution to the vba version control problem here: https://github.com/hilkoc/vbaDeveloper
The nice part about this is that it exports your code automatically, as soon as you save your workbook. Also, when you open a workbook, it imports the code.
You don't need to run any build scripts or maven commands and you don't need to make any changes to your workbooks. It works for all.
It has also solved the import problem where modules such as ModName are being imported as ModName1 into a duplicate module. The importing works as it should, even when doing it multiple times.
As a bonus, it comes with a simple code formatter, that allows you to format your vba code as you write it within the VBA Editor.
1
I just went through the whole build-process, and there are two issues, I would like to ask if you have figured out: 1. The Add-Ins ribbon isn't showing the vbaDeveloper menu, unless I run the refreshMenu() method provided in the Menu module 2. Exporting the code doesn't happen automatically, instead I have to trigger the action manually
– Marcus Mangelsdorf
Jul 1 '15 at 12:40
3
1 The menu will be created by the workbook_open event. For that to work build save and close the add-in. Then after opening it again the workbook_open event will be triggered, unless you manually disabled that with : Application.EnableEvents = False 2 The automatic import/export is disabled by default: github.com/hilkoc/vbaDeveloper/issues/8
– CodeKid
Jul 1 '15 at 15:10
add a comment |
There is an excellent solution to the vba version control problem here: https://github.com/hilkoc/vbaDeveloper
The nice part about this is that it exports your code automatically, as soon as you save your workbook. Also, when you open a workbook, it imports the code.
You don't need to run any build scripts or maven commands and you don't need to make any changes to your workbooks. It works for all.
It has also solved the import problem where modules such as ModName are being imported as ModName1 into a duplicate module. The importing works as it should, even when doing it multiple times.
As a bonus, it comes with a simple code formatter, that allows you to format your vba code as you write it within the VBA Editor.
There is an excellent solution to the vba version control problem here: https://github.com/hilkoc/vbaDeveloper
The nice part about this is that it exports your code automatically, as soon as you save your workbook. Also, when you open a workbook, it imports the code.
You don't need to run any build scripts or maven commands and you don't need to make any changes to your workbooks. It works for all.
It has also solved the import problem where modules such as ModName are being imported as ModName1 into a duplicate module. The importing works as it should, even when doing it multiple times.
As a bonus, it comes with a simple code formatter, that allows you to format your vba code as you write it within the VBA Editor.
answered Sep 22 '14 at 23:47
CodeKidCodeKid
813912
813912
1
I just went through the whole build-process, and there are two issues, I would like to ask if you have figured out: 1. The Add-Ins ribbon isn't showing the vbaDeveloper menu, unless I run the refreshMenu() method provided in the Menu module 2. Exporting the code doesn't happen automatically, instead I have to trigger the action manually
– Marcus Mangelsdorf
Jul 1 '15 at 12:40
3
1 The menu will be created by the workbook_open event. For that to work build save and close the add-in. Then after opening it again the workbook_open event will be triggered, unless you manually disabled that with : Application.EnableEvents = False 2 The automatic import/export is disabled by default: github.com/hilkoc/vbaDeveloper/issues/8
– CodeKid
Jul 1 '15 at 15:10
add a comment |
1
I just went through the whole build-process, and there are two issues, I would like to ask if you have figured out: 1. The Add-Ins ribbon isn't showing the vbaDeveloper menu, unless I run the refreshMenu() method provided in the Menu module 2. Exporting the code doesn't happen automatically, instead I have to trigger the action manually
– Marcus Mangelsdorf
Jul 1 '15 at 12:40
3
1 The menu will be created by the workbook_open event. For that to work build save and close the add-in. Then after opening it again the workbook_open event will be triggered, unless you manually disabled that with : Application.EnableEvents = False 2 The automatic import/export is disabled by default: github.com/hilkoc/vbaDeveloper/issues/8
– CodeKid
Jul 1 '15 at 15:10
1
1
I just went through the whole build-process, and there are two issues, I would like to ask if you have figured out: 1. The Add-Ins ribbon isn't showing the vbaDeveloper menu, unless I run the refreshMenu() method provided in the Menu module 2. Exporting the code doesn't happen automatically, instead I have to trigger the action manually
– Marcus Mangelsdorf
Jul 1 '15 at 12:40
I just went through the whole build-process, and there are two issues, I would like to ask if you have figured out: 1. The Add-Ins ribbon isn't showing the vbaDeveloper menu, unless I run the refreshMenu() method provided in the Menu module 2. Exporting the code doesn't happen automatically, instead I have to trigger the action manually
– Marcus Mangelsdorf
Jul 1 '15 at 12:40
3
3
1 The menu will be created by the workbook_open event. For that to work build save and close the add-in. Then after opening it again the workbook_open event will be triggered, unless you manually disabled that with : Application.EnableEvents = False 2 The automatic import/export is disabled by default: github.com/hilkoc/vbaDeveloper/issues/8
– CodeKid
Jul 1 '15 at 15:10
1 The menu will be created by the workbook_open event. For that to work build save and close the add-in. Then after opening it again the workbook_open event will be triggered, unless you manually disabled that with : Application.EnableEvents = False 2 The automatic import/export is disabled by default: github.com/hilkoc/vbaDeveloper/issues/8
– CodeKid
Jul 1 '15 at 15:10
add a comment |
I've been working on exactly this for months. I think I figured it out.
If the VB Project is trying to remove a module containing something in the call stack, it delays the removal until the call stack pops the module being replaced.
To avoid a module being in the call stack, launch your code with Application.OnTime
Private Sub Workbook_Open()
'WAS: module_library (1)
Application.OnTime (Now + TimeValue("00:00:01")), "load_library_kicker_firstiter"
End Sub
If you are self-healing your code like I am, you'll also have to launch your code that overwrites the 'calling' code with that same strategy.
I did not perform extensive testing yet, I am in total celebration mode, but this gets me extremely close to straightforward 99.9% self-healing code within a standalone .xls file without any other tricks
1
THANK YOU. This was my exact problem nearly 4 years later.
– enderland
Nov 11 '13 at 19:30
add a comment |
I've been working on exactly this for months. I think I figured it out.
If the VB Project is trying to remove a module containing something in the call stack, it delays the removal until the call stack pops the module being replaced.
To avoid a module being in the call stack, launch your code with Application.OnTime
Private Sub Workbook_Open()
'WAS: module_library (1)
Application.OnTime (Now + TimeValue("00:00:01")), "load_library_kicker_firstiter"
End Sub
If you are self-healing your code like I am, you'll also have to launch your code that overwrites the 'calling' code with that same strategy.
I did not perform extensive testing yet, I am in total celebration mode, but this gets me extremely close to straightforward 99.9% self-healing code within a standalone .xls file without any other tricks
1
THANK YOU. This was my exact problem nearly 4 years later.
– enderland
Nov 11 '13 at 19:30
add a comment |
I've been working on exactly this for months. I think I figured it out.
If the VB Project is trying to remove a module containing something in the call stack, it delays the removal until the call stack pops the module being replaced.
To avoid a module being in the call stack, launch your code with Application.OnTime
Private Sub Workbook_Open()
'WAS: module_library (1)
Application.OnTime (Now + TimeValue("00:00:01")), "load_library_kicker_firstiter"
End Sub
If you are self-healing your code like I am, you'll also have to launch your code that overwrites the 'calling' code with that same strategy.
I did not perform extensive testing yet, I am in total celebration mode, but this gets me extremely close to straightforward 99.9% self-healing code within a standalone .xls file without any other tricks
I've been working on exactly this for months. I think I figured it out.
If the VB Project is trying to remove a module containing something in the call stack, it delays the removal until the call stack pops the module being replaced.
To avoid a module being in the call stack, launch your code with Application.OnTime
Private Sub Workbook_Open()
'WAS: module_library (1)
Application.OnTime (Now + TimeValue("00:00:01")), "load_library_kicker_firstiter"
End Sub
If you are self-healing your code like I am, you'll also have to launch your code that overwrites the 'calling' code with that same strategy.
I did not perform extensive testing yet, I am in total celebration mode, but this gets me extremely close to straightforward 99.9% self-healing code within a standalone .xls file without any other tricks
edited Jun 8 '16 at 11:35
Jean-François Corbett
28.6k22109159
28.6k22109159
answered Nov 29 '09 at 15:52
user220879user220879
312
312
1
THANK YOU. This was my exact problem nearly 4 years later.
– enderland
Nov 11 '13 at 19:30
add a comment |
1
THANK YOU. This was my exact problem nearly 4 years later.
– enderland
Nov 11 '13 at 19:30
1
1
THANK YOU. This was my exact problem nearly 4 years later.
– enderland
Nov 11 '13 at 19:30
THANK YOU. This was my exact problem nearly 4 years later.
– enderland
Nov 11 '13 at 19:30
add a comment |
Usually the "Loader1" thing happens when Excel is asked to import a module and a module already exists with the same name. So if you import "Loader", then load it again and you'll get "Loader1". This would be because Excel doesn't know (or maybe just doesn't care) if it's really the same thing or a new chunk of functionality that just happens have the same module name, so it imports it anyway.
I can't think of a perfect solution, but I think I'd be inclined to try putting the load/unload logic in an add-in - that Workbook_Open thing looks a little vulnerable and having it in all workbooks is going to be a huge pain if the code ever needs to change (never say never). The XLA logic might be more complex (trickier to trap the necessary events, for one thing) but at least it'll only exist in one place.
Thanks for the answer Mike. You might be correct, an AddIn might be the only way of doing it. I was trying to avoid the AddIn solution, because I'd like to store the macros in SubVersion - so I'd prefer to store them as text files so I can merge and diff easily - rather than a binary XLA file.
– Jon Mills
Apr 3 '09 at 7:57
Maybe use a tiny addin to load the modules?
– Mike Woodhouse
Apr 3 '09 at 10:05
I'm not sure how using an AddIn is going to help in this situation. To load non-binary VBA modules into excel, I'm still going to have to run some sort of code when the Workbook is opened - and I don't think that keeping the Loader code in an AddIn will change the essence of the problem.
– Jon Mills
May 19 '09 at 14:27
Apparently the Addin approach does work. See my answer below. Their addin keeps all the import export logic in once place. It also hooks into the 'open' and 'save' events for excel, such that you don't need to write workbook_open() subs in all your workbooks.
– CodeKid
Sep 22 '14 at 23:58
add a comment |
Usually the "Loader1" thing happens when Excel is asked to import a module and a module already exists with the same name. So if you import "Loader", then load it again and you'll get "Loader1". This would be because Excel doesn't know (or maybe just doesn't care) if it's really the same thing or a new chunk of functionality that just happens have the same module name, so it imports it anyway.
I can't think of a perfect solution, but I think I'd be inclined to try putting the load/unload logic in an add-in - that Workbook_Open thing looks a little vulnerable and having it in all workbooks is going to be a huge pain if the code ever needs to change (never say never). The XLA logic might be more complex (trickier to trap the necessary events, for one thing) but at least it'll only exist in one place.
Thanks for the answer Mike. You might be correct, an AddIn might be the only way of doing it. I was trying to avoid the AddIn solution, because I'd like to store the macros in SubVersion - so I'd prefer to store them as text files so I can merge and diff easily - rather than a binary XLA file.
– Jon Mills
Apr 3 '09 at 7:57
Maybe use a tiny addin to load the modules?
– Mike Woodhouse
Apr 3 '09 at 10:05
I'm not sure how using an AddIn is going to help in this situation. To load non-binary VBA modules into excel, I'm still going to have to run some sort of code when the Workbook is opened - and I don't think that keeping the Loader code in an AddIn will change the essence of the problem.
– Jon Mills
May 19 '09 at 14:27
Apparently the Addin approach does work. See my answer below. Their addin keeps all the import export logic in once place. It also hooks into the 'open' and 'save' events for excel, such that you don't need to write workbook_open() subs in all your workbooks.
– CodeKid
Sep 22 '14 at 23:58
add a comment |
Usually the "Loader1" thing happens when Excel is asked to import a module and a module already exists with the same name. So if you import "Loader", then load it again and you'll get "Loader1". This would be because Excel doesn't know (or maybe just doesn't care) if it's really the same thing or a new chunk of functionality that just happens have the same module name, so it imports it anyway.
I can't think of a perfect solution, but I think I'd be inclined to try putting the load/unload logic in an add-in - that Workbook_Open thing looks a little vulnerable and having it in all workbooks is going to be a huge pain if the code ever needs to change (never say never). The XLA logic might be more complex (trickier to trap the necessary events, for one thing) but at least it'll only exist in one place.
Usually the "Loader1" thing happens when Excel is asked to import a module and a module already exists with the same name. So if you import "Loader", then load it again and you'll get "Loader1". This would be because Excel doesn't know (or maybe just doesn't care) if it's really the same thing or a new chunk of functionality that just happens have the same module name, so it imports it anyway.
I can't think of a perfect solution, but I think I'd be inclined to try putting the load/unload logic in an add-in - that Workbook_Open thing looks a little vulnerable and having it in all workbooks is going to be a huge pain if the code ever needs to change (never say never). The XLA logic might be more complex (trickier to trap the necessary events, for one thing) but at least it'll only exist in one place.
answered Apr 1 '09 at 11:41
Mike WoodhouseMike Woodhouse
43.4k1279119
43.4k1279119
Thanks for the answer Mike. You might be correct, an AddIn might be the only way of doing it. I was trying to avoid the AddIn solution, because I'd like to store the macros in SubVersion - so I'd prefer to store them as text files so I can merge and diff easily - rather than a binary XLA file.
– Jon Mills
Apr 3 '09 at 7:57
Maybe use a tiny addin to load the modules?
– Mike Woodhouse
Apr 3 '09 at 10:05
I'm not sure how using an AddIn is going to help in this situation. To load non-binary VBA modules into excel, I'm still going to have to run some sort of code when the Workbook is opened - and I don't think that keeping the Loader code in an AddIn will change the essence of the problem.
– Jon Mills
May 19 '09 at 14:27
Apparently the Addin approach does work. See my answer below. Their addin keeps all the import export logic in once place. It also hooks into the 'open' and 'save' events for excel, such that you don't need to write workbook_open() subs in all your workbooks.
– CodeKid
Sep 22 '14 at 23:58
add a comment |
Thanks for the answer Mike. You might be correct, an AddIn might be the only way of doing it. I was trying to avoid the AddIn solution, because I'd like to store the macros in SubVersion - so I'd prefer to store them as text files so I can merge and diff easily - rather than a binary XLA file.
– Jon Mills
Apr 3 '09 at 7:57
Maybe use a tiny addin to load the modules?
– Mike Woodhouse
Apr 3 '09 at 10:05
I'm not sure how using an AddIn is going to help in this situation. To load non-binary VBA modules into excel, I'm still going to have to run some sort of code when the Workbook is opened - and I don't think that keeping the Loader code in an AddIn will change the essence of the problem.
– Jon Mills
May 19 '09 at 14:27
Apparently the Addin approach does work. See my answer below. Their addin keeps all the import export logic in once place. It also hooks into the 'open' and 'save' events for excel, such that you don't need to write workbook_open() subs in all your workbooks.
– CodeKid
Sep 22 '14 at 23:58
Thanks for the answer Mike. You might be correct, an AddIn might be the only way of doing it. I was trying to avoid the AddIn solution, because I'd like to store the macros in SubVersion - so I'd prefer to store them as text files so I can merge and diff easily - rather than a binary XLA file.
– Jon Mills
Apr 3 '09 at 7:57
Thanks for the answer Mike. You might be correct, an AddIn might be the only way of doing it. I was trying to avoid the AddIn solution, because I'd like to store the macros in SubVersion - so I'd prefer to store them as text files so I can merge and diff easily - rather than a binary XLA file.
– Jon Mills
Apr 3 '09 at 7:57
Maybe use a tiny addin to load the modules?
– Mike Woodhouse
Apr 3 '09 at 10:05
Maybe use a tiny addin to load the modules?
– Mike Woodhouse
Apr 3 '09 at 10:05
I'm not sure how using an AddIn is going to help in this situation. To load non-binary VBA modules into excel, I'm still going to have to run some sort of code when the Workbook is opened - and I don't think that keeping the Loader code in an AddIn will change the essence of the problem.
– Jon Mills
May 19 '09 at 14:27
I'm not sure how using an AddIn is going to help in this situation. To load non-binary VBA modules into excel, I'm still going to have to run some sort of code when the Workbook is opened - and I don't think that keeping the Loader code in an AddIn will change the essence of the problem.
– Jon Mills
May 19 '09 at 14:27
Apparently the Addin approach does work. See my answer below. Their addin keeps all the import export logic in once place. It also hooks into the 'open' and 'save' events for excel, such that you don't need to write workbook_open() subs in all your workbooks.
– CodeKid
Sep 22 '14 at 23:58
Apparently the Addin approach does work. See my answer below. Their addin keeps all the import export logic in once place. It also hooks into the 'open' and 'save' events for excel, such that you don't need to write workbook_open() subs in all your workbooks.
– CodeKid
Sep 22 '14 at 23:58
add a comment |
Can't leave comment to comment
There is an excellent solution to the vba version control problem
here: https://github.com/hilkoc/vbaDeveloper
About saving custom VBAProjects using this XLAM.
Try this in Build.bas:
'===============
Public Sub testImport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.importVbaCode vbaProject
End Sub
'===============
Public Sub testExport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.exportVbaCode vbaProject
End Sub
'===============
This will export/import Active VBA Project.
add a comment |
Can't leave comment to comment
There is an excellent solution to the vba version control problem
here: https://github.com/hilkoc/vbaDeveloper
About saving custom VBAProjects using this XLAM.
Try this in Build.bas:
'===============
Public Sub testImport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.importVbaCode vbaProject
End Sub
'===============
Public Sub testExport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.exportVbaCode vbaProject
End Sub
'===============
This will export/import Active VBA Project.
add a comment |
Can't leave comment to comment
There is an excellent solution to the vba version control problem
here: https://github.com/hilkoc/vbaDeveloper
About saving custom VBAProjects using this XLAM.
Try this in Build.bas:
'===============
Public Sub testImport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.importVbaCode vbaProject
End Sub
'===============
Public Sub testExport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.exportVbaCode vbaProject
End Sub
'===============
This will export/import Active VBA Project.
Can't leave comment to comment
There is an excellent solution to the vba version control problem
here: https://github.com/hilkoc/vbaDeveloper
About saving custom VBAProjects using this XLAM.
Try this in Build.bas:
'===============
Public Sub testImport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.importVbaCode vbaProject
End Sub
'===============
Public Sub testExport()
Dim proj_name As String
Dim vbaProject As Object
'proj_name = "VBAProject"
'Set vbaProject = Application.VBE.VBProjects(proj_name)
Set vbaProject = Application.VBE.ActiveVBProject
proj_name = vbaProject.name
Build.exportVbaCode vbaProject
End Sub
'===============
This will export/import Active VBA Project.
edited Nov 13 '18 at 5:01
answered Nov 13 '18 at 4:54
VasilVasil
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f704759%2fsource-control-of-excel-vba-code-modules%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I forgot to add that I did some thinking and came up with this: grumpyop.wordpress.com/2009/04/20/… Note that there's also something called VBAMaven mentioned in the comments that looks like some external service that might help.
– Mike Woodhouse
May 19 '09 at 19:13