Excel VBA Code als Text exportieren
Zur Navigation springen
Zur Suche springen
VBA-Code
Public Sub ExportSourceFiles()
Dim Component As Object
Dim DestPath As String, myName As String
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
myName = objFSO.GetBaseName(ActiveWorkbook.Name) ' Name der Arbeitsmappe ohne Erweiterung
DestPath = ActiveWorkbook.Path & "\" & myName & "-VBACode\"
If Not FolderDa(DestPath) Then
MkDir DestPath
End If
For Each Component In Application.VBE.ActiveVBProject.VBComponents
If Component.Type = 100 Or Component.Type = 1 Then
Component.Export DestPath & Component.Name & ToFileExtension(Component.Type)
End If
Next
End Sub
Private Function ToFileExtension(vbeComponentType As Long) As String
Select Case vbeComponentType
Case 100 'vbext_ComponentType.vbext_ct_ClassModule
ToFileExtension = "-cls.txt"
Case 1 'vbext_ComponentType.vbext_ct_StdModule
ToFileExtension = "-bas.txt"
Case Else
ToFileExtension = vbNullString
End Select
End Function