Sub AllCodeToTextFile(strFolder As String, Optional strFileExt As String = "txt")
Dim fso As Object
Dim fsoFile As Object
Dim strMod As String
Dim mdl As Object
Dim i As Integer
Dim strFileName As String
Dim strDate As String
strFileName = Replace(CurrentProject.Name, ".", "-")
strDate = Format(Now(), "yyyy-mm-dd-hh-nn-ss")
Set fso = CreateObject("Scripting.FileSystemObject")
If Right$(strFolder, 1) = "\" Then
Else
strFolder = strFolder & "\"
End If
strFolder = (strFolder & strFileName & "-" & strDate & "." & strFileExt)
Set fsoFile = fso.CreateTextFile(strFolder)
For Each mdl In VBE.ActiveVBProject.VBComponents
i = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.CountOfLines
strMod = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.Lines(1, i)
fsoFile.WriteLine String$(55, "=") & vbCrLf & mdl.Name _
& vbCrLf & String$(55, "=") & vbCrLf & strMod
Next
MsgBox "Code has been saved to " & strFolder
fsoFile.Close
Set fso = Nothing
End Sub