2012-12-13 111 views
11

可能重复:
Any way to automatically move contents of immediate window into a text file?如何将VBA Debug.Print输出记录到文本文件?

是否有可能日志Debug.Print输出到一个文本文件,而不是在Excel VBA立即窗口?

+1

没有,你需要直接写入文件。 –

+1

写入(或追加)到CSV文件是有道理的。 http://stackoverflow.com/questions/9442215/reading-and-writing-a-csv-file-using-filesystemobject/9442846#9442846 – brettdj

+1

看看这里,你使用'FileSystemObject' [Remou的文章](http:// www.tek-tips.com/viewthread.cfm?qid=1308229)如果您仍然遇到问题,请通过追加您尝试过的任何相关代码来更新问题。然后,我们很乐意帮助你进一步:) – bonCodigo

回答

22

你应该可以看到由让·弗朗索瓦·科贝特here神话般的答案:

正如他指出,这是毫无意义的写即时窗口,然后复制并粘贴它时,你可以只写一个输出TXT文件在同一时间(或只是txt文件,如果这是你想要的)。从他的回答

例子:

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 
+0

感谢您蒸馏此。它对我很好。 – Igor

相关问题