Sub 產生文字檔()
xT = "文字檔內容"
xFile = thisworkbook.path & "\" & format(date,"yyyymmdd") & ".txt"
Open xFile For Output As #1 'Output覆蓋舊資料
Print #1, xT
Close #1
End Sub
Sub 產生文字檔_2()
xT = "文字檔內容"
xFile = thisworkbook.path & "\" & format(date,"yyyymmdd") & ".txt"
Open xFile For Append As #1 'Append-寫在檔案的尾端...累增
Print #1, xT
Close #1
End Sub
Option Explicit
Sub 產生文字檔_Append_寫在檔案的尾端_累增()
Dim xT$, xFile$
xT = "歡迎一起來學習!論壇其實沒什麼門檻!潛規則就是虛心學習!"
xFile = ThisWorkbook.Path & "\" & Format(Date, "yyyymmdd") & ".txt"
Open xFile For Append As #1 'Append-寫在檔案的尾端...累增
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/open-statement
Print #1, xT
Close #1
End Sub
謝謝前輩指導
謝謝論壇
Option Explicit
Sub CreateObject_Scripting_FileSystemObject_AND_OpenTextFile()
Dim fs, a
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(ThisWorkbook.Path & "\" & Format(Date, "yyyymmdd") & ".txt", True)
a.WriteLine ("This is a test.")
a.Close
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/filesystemobject-object
End Sub
Sub CreateObject_ADODB_Stream()
'https://club.excelhome.net/thread-868093-1-1.html
End Sub