TXTからデータを読み込む | カメレオンのVBA

カメレオンのVBA

VBAの私的メモ書き

sub test()
Dim buf As String, n As Long,myBuf as variant , i as Long Dim myTxtFile as string
 myTxtFile = "xxxxx.txt" '読み込むテキストファイル名
’テキストファイルはエクセルブックと同じフォルダにあると仮定する

 Open ThisWorkbook.Path & "\" & myTxtFile For Input As #1   Do Until EOF(1)   Line Input #1, buf
  myBuf = Split(buf,chr(9)) 'chr(9)はタブスペースを表す
  For i = 1 to Ubound(myBuf) '1~myBufの最大配列数まで繰り返す    Cells(n, i).value = myBuf(i) '書き込み開始   Next i
 Loop
 Close #1

end sub