Exporting VBA code from Multiple Excel documents to put into version control [closed] Exporting VBA code from Multiple Excel documents to put into version control [closed] vba vba

Exporting VBA code from Multiple Excel documents to put into version control [closed]


You'll find a tool for this here:

http://www.pretentiousname.com/excel_extractvba/index.html

It's a VBS script that automates excel. You can modify it according to your needs - note that it isn't perfect (read the webpage for caveats).

option explicitConst vbext_ct_ClassModule = 2Const vbext_ct_Document = 100Const vbext_ct_MSForm = 3Const vbext_ct_StdModule = 1MainSub Main    Dim xl    Dim fs    Dim WBook    Dim VBComp    Dim Sfx    Dim ExportFolder    If Wscript.Arguments.Count <> 1 Then        MsgBox "As the only argument, give the FULL path to an XLS file to extract all the VBA from it."    Else        Set xl = CreateObject("Excel.Application")        Set fs = CreateObject("Scripting.FileSystemObject")        xl.Visible = true        Set WBook = xl.Workbooks.Open(Trim(wScript.Arguments(0)))        ExportFolder = WBook.Path & "\" & fs.GetBaseName(WBook.Name)        fs.CreateFolder(ExportFolder)        For Each VBComp In WBook.VBProject.VBComponents            Select Case VBComp.Type                Case vbext_ct_ClassModule, vbext_ct_Document                    Sfx = ".cls"                Case vbext_ct_MSForm                    Sfx = ".frm"                Case vbext_ct_StdModule                    Sfx = ".bas"                Case Else                    Sfx = ""            End Select            If Sfx <> "" Then                On Error Resume Next                Err.Clear                VBComp.Export ExportFolder & "\" & VBComp.Name & Sfx                If Err.Number <> 0 Then                    MsgBox "Failed to export " & ExportFolder & "\" & VBComp.Name & Sfx                End If                On Error Goto 0            End If        Next        xl.Quit    End IfEnd Sub

-Adam


I have used this successfully for the past few years to export my code and save it. I can confirm it works in Office 2003, 2007. I assume it works in 2000 as well.

http://www.codeproject.com/KB/office/SourceTools.aspx


When I was doing a lot of Excel VBA development I got into the habit of exporting to the text format for each file (module, etc) each time I made a change (from the context menu). I kept those files in source control alongside the XLA binary. This worked pretty well for me and didn't require any external tools.