前回までで、jwc_temp.txt のデータをワークシートに取り込んで、編集しました。
このデータを jwc_temp.txt に戻すところを解説します。
Private Sub Workbook_Open()
Dim editTEXTDATA
Dim myPath
Dim buf
Dim cnt As Long
Dim i As Long
Dim RowEnd As Long
myPath = ThisWorkbook.Path
editTEXTDATA = myPath & "\jwc_temp.txt"
cnt = 1
Open editTEXTDATA For Input As #1
Do
Line Input #1, buf
Worksheets(1).Cells(cnt, 1).Value = buf
cnt = cnt + 1
Loop Until EOF(1)
Close #1
With Worksheets(1)
.Cells(1, 1).EntireRow.Delete
RowEnd = .Range("A1").End(xlDown).Row
For i = 1 To RowEnd
If .Cells(i, 1) = "#" Then
.Cells(i, 1).EntireRow.Insert
.Cells(i, 1).Value = "0 0 100 100"
Exit For
End If
Next i
Open editTEXTDATA For Output As #1
RowEnd = .Range("A1").End(xlDown).Row
For i = 1 To RowEnd
Print #1, .Cells(i, 1).Value
Next i
Close #1
Open editTEXTDATA For Output As #1 <---追加
RowEnd = .Range("A1").End(xlDown).Row
For i = 1 To RowEnd
Print #1, .Cells(i, 1).Value
Next i
Close #1 <---
End With
End Sub
追加<---の所が、今回のコードです。
テキストデータに書き込むには、
OPEN ~ で、For の後に、OUTPUTを使います。
その後、print で、1行づつ書き込んでいきます。
動画で解説しましたので、参考にして下さい。