0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

vbaでファイル出力する方法

Posted at
Sub WriteTextToFileInSameFolder()
    Dim filePath As String
    Dim fileNumber As Integer
    Dim textData As String

    ' マクロを実行したファイルと同じフォルダにファイルパスを指定
    filePath = ThisWorkbook.Path & "\output.txt"
    
    ' 書き込むテキストデータ
    textData = "This is a sample text written to the file in the same folder."

    ' ファイル番号を取得
    fileNumber = FreeFile

    ' ファイルを出力モードで開く(新規作成または上書き)
    Open filePath For Output As fileNumber

    ' ファイルにテキストを書き込む
    Print #fileNumber, textData

    ' ファイルを閉じる
    Close fileNumber

    MsgBox "Text has been written to " & filePath
End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?