1. 程式人生 > >VBA建立文字檔案、讀寫文字檔案

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

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