|
概ね、こんな感じです。コードの意味を、よくチェックしてから使って下さい。
Sub CSV読み込み()
Dim MyF As String, Buf As String
Dim Ary As Variant
Dim SCnt As Integer, Num As Integer
Const SvFol As String = _
"C:\Documents and Settings\User\My Documents\My CSV"
'↑保存先フォルダーのパスを正確に指定する。
ChDir SvFol
With Application
MyF = .GetOpenFilename("CSVファイル(*.csv),*.csv")
If MyF = "False" Then Exit Sub
.ScreenUpdating = False
End With
SCnt = Worksheets.Count
Open MyF For Input Access Read As #1
Do Until EOF(1)
Line Input #1, Buf
Ary = Split(Buf, ",")
Num = Val(Ary(0))
If Num <= SCnt Then
Worksheets(Num).Range("A65536").End(xlUp) _
.Offset(1).Resize(, UBound(Ary) + 1).Value = Ary
Else
Debug.Print Buf
End If
Erase Ary
Loop
Close #1
With Application
ChDir .DefaultFilePath
.ScreenUpdating = True
End With
End Sub
|
|