MeldrethMan
Technical User
Any help would be appreciated.
A run-time error -2147024809, 'Invalid procedure call or argument' has suddenly appeared in a procedure that worked fine in earlier editions. The changes I've made since then have been cosmetic ones on form and report formats.
I'm using Call AllCodeToTextFile("C:Code", "txt") on a form's command button and the procedure code is as below.
Debug highlights the middle line of the For statement, strmod = VBE. etc
When it works this is a very useful way of getting all code posted out to a text file.
Code:
Sub AllCodeToTextFile(strFolder As String, strFileExt As String)
Dim fs As Object
Dim F As Object[highlight #FCE94F][/highlight]
Dim strMod As String
Dim mdl As Object
Dim i As Integer
Set fs = CreateObject("Scripting.FileSystemObject")
If Right(strFolder, 1) = "" Then
'Do Nothing
Else
strFolder = strFolder & ""
End If
' Establish the file name using the CurrentProject Name
strFolder = (strFolder & Replace(CurrentProject.Name, ".", "") & "." & strFileExt)
'Set up the file.
Set F = fs.CreateTextFile(strFolder)
'For each component in the project ...
For Each mdl In VBE.ActiveVBProject.VBComponents
i = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.CountOfLines
[highlight #FCE94F]strMod = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.Lines(1, i)[/highlight]
F.WriteLine String(55, "=") & vbCrLf & mdl.Name & vbCrLf & String(55, "=") & vbCrLf & strMod
Next mdl
MsgBox "Code has been saved to " & strFolder
'Close eveything
F.Close
Set fs = Nothing
End Sub