|
どちらもアクティブシートに対しての処理です。作成・読み込みをするファイルを
仮に C:\temp\Data.txt とします。
[テキストファイルへ書き出し]
Sub Data_Exp()
Dim C As Range
Dim SAry As Variant
Dim Buf As String
Const MyF As String = "C:\temp\Data.txt"
If Dir(MyF) <> "" Then Kill MyF
Open MyF For Output Access Write As #1
For Each C In Range("A1", Range("A65536").End(xlUp))
With WorksheetFunction
SAry = .Transpose(.Transpose(C.Resize(, 4).Value))
End With
Buf = Join(SAry, ",")
Print #1, Buf
Erase SAry
Next
Close #1
End Sub
[テキストファイルから読み込み]
Sub Data_Imp()
Dim i As Long
Dim SAry As Variant
Dim Buf As String
Const MyF As String = "C:\temp\Data.txt"
If Dir(MyF) = "" Then
MsgBox "開くテキストファイルが見つかりません", 48
Exit Sub
End If
Open MyF For Input Access Read As #1
Do Until EOF(1)
i = i + 1
Line Input #1, Buf
SAry = Split(Buf, ",")
Cells(i, 1).Resize(, 4).Value = SAry
Erase SAry
Loop
Close #1
End Sub
|
|