Forked from steve-jansen/ExportVisualBasicCode.bas.vb
Last active
January 2, 2018 16:38
-
-
Save marcucciboy2/204a8a27e2179a7dae1aee40c543e4de to your computer and use it in GitHub Desktop.
Excel macro to export all VBA source code in this project to text files for proper source control versioning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Excel macro to export all VBA source code in this project to text files for proper source control versioning | |
' Requires enabling the Excel setting in Options/Trust Center/Trust Center Settings/Macro Settings/Trust access to the VBA project object model | |
' changes: | |
' - only exports normal modules | |
' - uses mkdir instead of fso | |
' - does not use statusbar | |
Public Sub ExportVisualBasicCode() | |
Dim directory As String | |
directory = "C:\" | |
If Len(Dir(directory, vbDirectory)) = 0 Then | |
MkDir directory | |
End If | |
Dim VBComponent As Object | |
Dim path As String | |
For Each VBComponent In ActiveWorkbook.VBProject.VBComponents | |
' Module = 1 '".bas" | |
' ClassModule = 2 '".cls" | |
' Form = 3 '".frm" | |
' Document = 100 '".cls" | |
' Else '".txt" | |
If VBComponent.Type = 1 Then | |
On Error Resume Next | |
Err.Clear | |
path = directory & "\" & VBComponent.Name & ".bas" | |
Call VBComponent.Export(path) | |
If Err.Number <> 0 Then | |
Call MsgBox("Failed to export " & VBComponent.Name & " to " & path, vbCritical) | |
Else | |
Debug.Print Trim$("Exported " & VBComponent.Name & ": " & path) | |
End If | |
On Error GoTo 0 | |
End If | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment