|
仮にテキストファイルの保存先が
C:\Documents and Settings\User\My Documents\My Text
てあるとして、Sheet1 に読み込むなら
Sub Read_MyText()
Dim MyF As String, Buf As String
Dim Fnum As Long, i As Long
Dim Ary As Variant
Const Ph As String = _
"C:\Documents and Settings\User\My Documents\My Text\"
MyF = Dir(Ph & "*.txt"): i = 2
Do Until MyF = ""
Fnum = FreeFile()
Open Ph & MyF For Input Access Read As #Fnum
Do Until EOF(Fnum)
Line Input #Fnum, Buf
Ary = Split(Buf, ",") '区切り文字をカンマとする。
With Worksheets("Sheet1")
.Cells(i, 2).Value = Left$(MyF, Len(MyF) - 4)
.Cells(i, 3).Resize(, UBound(Ary) + 1).Value = Ary
End With
i = i + 1: Erase Ary
Loop
Close #Fnum
MyF = Dir()
Loop
MsgBox "全てのテキストファイルデータを読み込みました", 64
End Sub
|
|