如何将 VBA Debug.Print 输出记录到文本文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13853376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I log VBA Debug.Print output to a text file?
提问by DPD
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?
是否可以将 Debug.Print 输出记录到文本文件而不是 Excel VBA 中的立即窗口?
回答by aevanko
You should see the fabulous answer by Jean-Fran?ois Corbett here:
?你应该看到让-弗朗索瓦美妙的答案OIS科贝特在这里:
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).
正如他所说,写入即时窗口是没有意义的,然后在您可以同时写入输出 txt 文件时复制并粘贴它(或者只是 txt 文件,如果这是您想要的)。
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