VBA建立文字檔案、讀寫文字檔案

無名_四葉草發表於2020-04-04
Private Sub CommandButton1_Click()
    Dim gPath As String
    Dim sFile As Object, Fso As Object
    
    gPath = Application.ActiveWorkbook.Path
    Set Fso = CreateObject("Scripting.FileSystemObject")
    Set sFile = Fso.CreateTextFile(gPath & "/TestFile.txt", True)
    sFile.WriteLine ("CreateTextFile Test")
    sFile.WriteLine ("CreateTextFile Test1")
    sFile.WriteLine ("CreateTextFile Test2")
    sFile.WriteLine ("CreateTextFile Test2")
    sFile.Close
    Set sFile = Nothing
    Set Fso = Nothing

  
End Sub
轉自:http://blog.csdn.net/merry1205/article/details/5786273

相關文章