How to save messages from VBA code to a text file?

  • Thread starter Thread starter Jojo
  • Start date Start date
J

Jojo

I am new to VBA coding. I would like to save messages to a log file so
I can monitor my Macro's process by the messages in the log file. Can
anyone give me a sample code to save messages to a file?

Thanks.

-Jojo
 
Well, macros in Access aren't VBA coding, but I'll assuming you really do
want VBA.

I typically create a sub like the following:

Sub DebugPrint(OutputMessage As String)
Dim intFile As Integer
Dim strFile As String

strFile = CurrentProject.Path & "/Output.txt"
intFile = FreeFile
Open strFile For Append As #intFile
Write #intFile, OutputMessage
Close #intFile

End Sub

I then use this like:

DebugPrint "The routine is calculating the variance"

or

Call DebugPrint("The routine is calculating the variance")
 
Douglas J. Steele said:
Well, macros in Access aren't VBA coding, but I'll assuming you really do
want VBA.

I typically create a sub like the following:

Sub DebugPrint(OutputMessage As String)
Dim intFile As Integer
Dim strFile As String

strFile = CurrentProject.Path & "/Output.txt"
intFile = FreeFile
Open strFile For Append As #intFile
Write #intFile, OutputMessage
Close #intFile

End Sub

I then use this like:

DebugPrint "The routine is calculating the variance"

or

Call DebugPrint("The routine is calculating the variance")
 
Back
Top