|
ま、こんな感じで。
Sub Get_CSV_Data()
Dim FSO As Object, MyCSV As Object
Dim MyF As String, Buf As String
Dim GetR As Long, i As Long
Dim Ary As Variant
With Application
MyF = .GetOpenFilename("CSVファイル(*.csv),*.csv")
If MyF = "False" Then Exit Sub
.ScreenUpdating = False
End With
Set FSO = CreateObject("Scripting.FileSystemObject")
GetR = FSO.OpenTextFile(MyF, 8).Line
If GetR = 1 Then
MsgBox "そのファイルにはデータがありません", 48: GoTo ELine
End If
Worksheets("Sheet1").Activate: Cells.ClearContents
Set MyCSV = FSO.OpenTextFile(MyF, 1)
Do Until MyCSV.AtEndOfStream
Buf = MyCSV.ReadLine
Ary = Split(Buf, ",")
If Ary(0) = "Z01" Or Ary(0) = "0Z01" Then
If Ary(1) = "ZZ" Or Ary(1) = "0ZZ" Then
i = i + 1
Cells(i, 1).Resize(, 6).Value = _
Array(Ary(0), Ary(1), Ary(2), Ary(4), _
Ary(7), Ary(10))
End If
End If
Erase Ary
Loop
MyCSV.Close: Set MyCSV = Nothing
MsgBox "データの抽出を終了しました", 64
ELine:
Set FSO = Nothing: Application.ScreenUpdating = True
End Sub
|
|