|
>毎回MID関数で位置・長さを定義
というところから推測すると、固定長のテキストですか ?
それならLeft,Right,Mid関数を使っても問題ないと思います。
ただし、わざわざワークシートに書き出す必要はありません。
以下のようにして、読み込みと書き出しを一度で済ませてしまえば
良いのです。
Sub Mk_ReNewText()
Dim MyF As String, MyF2 As String
Dim Buf1 As String, Buf2 As String
Dim Fnum1 As Long, Fnum2 As Long
MyF = Application _
.GetOpenFilename("テキストファイル(*.txt),*.txt")
If MyF = "False" Then Exit Sub
MyF2 = Left$(MyF, Len(MyF) - 4) & "ReNew.txt"
Fnum1 = FreeFile()
Open MyF For Input Access Read As #Fnum1
Fnum2 = FreeFile()
Open MyF2 For OutPut Access Write As #Fnum2
Do Until EOF(Fnum1)
Line Input #Fnum1, Buf1
Buf2 = Left$(Buf1, 2) & "," & Mid$(Buf1, 3, 3) & _
"," & Mid$(Buf1, 6, 2) & "," & Right$(Buf1, 2)
Print #Fnum2, Buf2
Buf1 = "": Buf2 = ""
Loop
Close #Fnum2: Close #Fnum1
MsgBox Dir(MyF2) & vbLf & "を作成しました", 64
End Sub
|
|