Skip to content

Instantly share code, notes, and snippets.

@0x4a
Last active April 26, 2017 16:56
Show Gist options
  • Save 0x4a/410e1c3df4c2f1bb2e430fa73d4ab2a5 to your computer and use it in GitHub Desktop.
Save 0x4a/410e1c3df4c2f1bb2e430fa73d4ab2a5 to your computer and use it in GitHub Desktop.
Excel VBA log-to-file
Private Const VERBOSE As Boolean = false
Private Function log(text as String)
Debug.Print text
If VERBOSE Then
Dim n As Integer
n = FreeFile()
Dim File As String
File = ActiveWorkbook.Path & "\debug.txt"
If Dir(File) = "" Then
Open File For Output As #n
Close #n
End If
Open File For Append As #n
Print #n, "[" & Format(Now, "YYYY-MM-DD hh:mm:ss") & "] " & text
Close #n
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment