Created
December 8, 2013 09:48
-
-
Save windwiny/7855281 to your computer and use it in GitHub Desktop.
Extract VBA code to text files (for diffing)
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
Option Explicit | |
Function GetFolder(strPath As String) As String | |
Dim fldr As FileDialog | |
Dim sItem As String | |
Set fldr = Application.FileDialog(msoFileDialogFolderPicker) | |
With fldr | |
.Title = "Select a Folder" | |
.AllowMultiSelect = False | |
.InitialFileName = strPath | |
If .Show <> -1 Then GoTo NextCode | |
sItem = .SelectedItems(1) | |
End With | |
NextCode: | |
GetFolder = sItem | |
Set fldr = Nothing | |
End Function | |
' Extract VBA code to text files (for diffing) | |
Public Sub export_vba() | |
Dim Exportfolder As String | |
Dim Exportfile As String | |
Dim Sfx As String | |
Dim VBComp | |
Const vbext_ct_ClassModule = 2 | |
Const vbext_ct_Document = 100 | |
Const vbext_ct_MSForm = 3 | |
Const vbext_ct_StdModule = 1 | |
Exportfolder = GetFolder("c:\") | |
If Exportfolder = "" Then | |
MsgBox "Not select a folder" | |
Exit Sub | |
End If | |
Debug.Print "== Begin Extract VBA code:" | |
For Each VBComp In Application.ActiveWorkbook.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 | |
Exportfile = Exportfolder & "\" & VBComp.name & Sfx | |
Debug.Print Exportfile | |
VBComp.export Exportfile | |
If Err.Number <> 0 Then | |
MsgBox "Failed to export " & Exportfile | |
End If | |
On Error GoTo 0 | |
End If | |
Next | |
Debug.Print "== End Extract VBA code." | |
End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment