Worksheets("Sheet1").Activate
Range("A1:D65536").Select
Selection.ClearContents
Range("A1").Select
fn = ActiveWorkbook.FullName ' ブックのフル名称を得る
POS = InStrRev(fn, "\") ' うしろから \ を探す
curpath = Mid(fn, 1, POS) ' 先頭から \ の位置までを取り出す
cnstr = "text;" & curpath & "sample.csv" ' 読み込みたいファイルを指定
With ActiveSheet.QueryTables.Add(Connection:=cnstr, _
Destination:=Range("A1"))
.TextFileCommaDelimiter = True ' カンマごとにセルを区切る
.TextFileColumnDataTypes = Array(2, 1, 1, 1) ' 1は標準 2は文字列
.Refresh
.Delete
End With
Range("A1:D65536").Select
Selection.ClearContents
Range("A1").Select
fn = ActiveWorkbook.FullName ' ブックのフル名称を得る
POS = InStrRev(fn, "\") ' うしろから \ を探す
curpath = Mid(fn, 1, POS) ' 先頭から \ の位置までを取り出す
cnstr = "text;" & curpath & "sample.csv" ' 読み込みたいファイルを指定
With ActiveSheet.QueryTables.Add(Connection:=cnstr, _
Destination:=Range("A1"))
.TextFileCommaDelimiter = True ' カンマごとにセルを区切る
.TextFileColumnDataTypes = Array(2, 1, 1, 1) ' 1は標準 2は文字列
.Refresh
.Delete
End With