Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I log VBA Debug.Print output to a text file? [duplicate]

Tags:

vba

Possible Duplicate:
Any way to automatically move contents of immediate window into a text file?

Is it possible to log the Debug.Print output to a text file instead of the Immediate window in Excel VBA?

like image 422
DPD Avatar asked Dec 13 '12 05:12

DPD


People also ask

How do I read a Debug print?

Messages being output via Debug. Print will be displayed in the immediate window which you can open by pressing Ctrl + G .

How does Debug print work in VBA?

Debug. Print is telling VBA to print that information in the Immediate Window. This can be useful when you want to see the value of a variable in a certain line of your code, without having to store the variable somewhere in the workbook or show it in a message box.

How do I print text in Excel VBA?

Steps to Open Immediate Window and See the OutputPress Ctrl + G or click on the 'View' menu in the VBA editor. Choose the option 'Immediate Window'. Place the cursor in the Window and again run the code. Observe the output in the window.


1 Answers

You should see the fabulous answer by Jean-François Corbett here:

As he states, it makes little sense to write to the immediate window, then copy and paste it when you could just write to an output txt file at the same time (or just the txt file if that is what you want).

Example from his answer:

Dim s As String
Dim n As Integer

n = FreeFile()
Open "C:\test.txt" For Output As #n

s = "Hello, world!"
Debug.Print s ' write to immediate
Print #n, s ' write to file

Close #n
like image 106
aevanko Avatar answered Sep 28 '22 07:09

aevanko