Public Function DocumentModule(RootDirectory As String, ExportBas As Boolean, ExportText As Boolean)
'Make sure a root directory was specified
If Len(RootDirectory) = 0 Then
Exit Function
End If
Dim objProj As VBProject
Dim objComponent As VBComponent
Dim intFile As Integer
Dim strModule As String
Set objProj = Application.VBE.ActiveVBProject
For Each objComponent In objProj.VBComponents
'Export the files as *.bas files
If ExportBas Then
objComponent.Export RootDirectory & "\" & objComponent.Name & ".bas"
End If
'Export the modules as *.txt files
If ExportText Then
intFile = FreeFile
Open RootDirectory & "\" & objComponent.Name & ".txt" For Output As #intFile
strModule = objComponent.CodeModule.Lines(1, objComponent.CodeModule.CountOfLines)
Print #intFile, strModule
Close #intFile
End If
Next objComponent
'Clean up
Set objComponent = Nothing
Set objProj = Nothing
End Function