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
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme