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?
Messages being output via Debug. Print will be displayed in the immediate window which you can open by pressing Ctrl + G .
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With