0
我想使用VBA編寫文件。我的代碼如下。它第一次工作,但當我關閉Excel文件(.xlsm)並嘗試再次使用它時,它不起作用。錯誤寫入文件vba
運行宏,但新的文件沒有出現
Sub LogInformation(LogMessage As String)
Const LogFileName As String = "TEXTFILE.db"
Dim FileNum As Integer
FileNum = FreeFile ' next file number
Open LogFileName For Append As #FileNum ' creates the file if it doesn't exist
Print #FileNum, LogMessage ' write information at the end of the text file
Close #FileNum ' close the file
End Sub
是否因爲'FileNum = FreeFile'總是找到'Next'文件號? – user959631 2011-12-23 21:30:58
It aways returns 1 – Makah 2011-12-23 21:32:42
Ohh好吧,我真的不知道VBA很多,抱歉Ohh剛剛意識到,它只在文件不存在時才創建文件。也許這就是問題所在? – user959631 2011-12-23 21:34:34