ファイル作成マクロ
Excelシートに①ファイル名称、②内容を記述し、ファイルを作成するマクロ。
コード内で指定している拡張子.txtを変更すれば、.batファイル、.cmdファイルなども作成可能。
*ダウンロード↓
*キャプチャ
*コード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
Option Explicit Sub ボタン1_Click() '初期処理 Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets(1) Dim fileCount As Long fileCount = 2 '本処理 Do While ws.Cells(fileCount, 1).Value <> "" 'ファイル作成 Dim datFile As String datFile = ActiveWorkbook.Path & "\" & ws.Cells(fileCount, 1) & ws.Cells(fileCount, 2) & ws.Cells(fileCount, 3) & ws.Cells(fileCount, 4) & ".txt" 'ファイル編集 Open datFile For Output As #1 Print #1, "ProgramID = " & ws.Cells(fileCount, 5).Value Print #1, "Number = " & ws.Cells(fileCount, 6).Value Print #1, ws.Cells(fileCount, 7).Value Print #1, ws.Cells(fileCount, 8).Value Close #1 fileCount = fileCount + 1 Loop MsgBox (fileCount - 2) & "件のファイルを作成しました。" End Sub |