2012-12-13 113 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

相關問題