ray88’s diary

お仕事で困ったとき用の自分用の覚書

テキストファイルを生成する

Sub test1()
    Dim strPath As String
    Dim FSO As Object

    'ファイルシステムオブジェクトをインスタンス化
    Set FSO = CreateObject("Scripting.FilesystemObject")

    '生成するファイルのパスを指定
    strPath = "C:\Users\デスクトップ\test.csv"

    'ファイルを生成
    FSO.createtextfile (strPath)

    'オブジェクト変数を解放
    Set FSO = Nothing

End Sub

または

Sub test2()

     Dim strPath As String
       
     strPath = "C:\Users\デスクトップ\test.csv"
    
     With CreateObject("Scripting.FilesystemObject")
    
        .createtextfile (strPath)
    
     End With

End Sub