Sub Test()
Dim wsImport As Worksheet
Set wsImport = Worksheets("Sheet1") 'CSVデータを取り込み用シート
'読み込むファイル
Dim strFilePath As String
strFilePath = "C:\Users\take2\Desktop\VBA\test.csv"
Dim queryTb As QueryTable
Set queryTb = wsImport.QueryTables.Add(Connection:="TEXT;" & strFilePath, Destination:=wsImport.Range("A1")) ' CSV を開く
With queryTb
.TextFilePlatform = 932 ' 文字コードを指定
.TextFileParseType = xlDelimited ' 区切り文字の形式
.TextFileCommaDelimiter = True ' カンマ区切り
.RefreshStyle = xlOverwriteCells ' セルに書き込む方式
.Refresh ' データを表示
.Delete ' CSVファイルとの接続を解除
End With
MaxCol = wsImport.UsedRange.Columns(wsImport.UsedRange.Columns.Count).Column
MaxRow = wsImport.UsedRange.Rows(wsImport.UsedRange.Rows.Count).Row
arr = Range(Cells(1, 1).Address, Cells(MaxRow, MaxCol).Address)
End Sub
Sub aaaa()
Dim wsImport As Worksheet
Workbooks.Open "C:\Users\take2\Desktop\VBA\test.csv"
Set wsImport = Worksheets("test") 'CSVデータを取り込み用シート
MaxCol = wsImport.UsedRange.Columns(wsImport.UsedRange.Columns.Count).Column
MaxRow = wsImport.UsedRange.Rows(wsImport.UsedRange.Rows.Count).Row
arr = Range(Cells(1, 1).Address, Cells(MaxRow, MaxCol).Address)
End Sub
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme