Output to .TXT-file?

C

Charlotte E.

Hi Guys,


I'm aware that you can make a small log to the Immediate window by using
Debug.Print along the way during the execution of your code, but is it also
possible to do so to a .TXT-file?


TIA,
 
J

Joe via OfficeKB.com

Yes. Try some version of this.


Sub LogInformation(LogMessage As String)
Const LogFileName As String = "F:\Shared\CVG\Quality\Malcolms\User.txt"
Dim FileNum As Integer
FileNum = FreeFile ' next file number
Open LogFileName For Append As #FileNum ' creates the file if it
doesn't exist
Print #FileNum, LogMessage ' write information at the end of the text
file
Close #FileNum ' close the file
End Sub


Private Sub Workbook_Open()
LogInformation ThisWorkbook.Name & " opened by " & _
Application.UserName & " " & Format(Date, "yyyy-mm-dd")
End Sub
 
C

Charlotte E.

Worked like a charm :)

Thanks...



Joe via OfficeKB.com said:
Yes. Try some version of this.


Sub LogInformation(LogMessage As String)
Const LogFileName As String = "F:\Shared\CVG\Quality\Malcolms\User.txt"
Dim FileNum As Integer
FileNum = FreeFile ' next file number
Open LogFileName For Append As #FileNum ' creates the file if it
doesn't exist
Print #FileNum, LogMessage ' write information at the end of the
text
file
Close #FileNum ' close the file
End Sub


Private Sub Workbook_Open()
LogInformation ThisWorkbook.Name & " opened by " & _
Application.UserName & " " & Format(Date, "yyyy-mm-dd")
End Sub
 
Top