Set csvTable = (Range:=Selection.Range, NumRows:=UBound(csvLines), NumColumns:=10, _
#Microsoft word add in import csv into table code#
You have omitted csvData(0)(2) in the above code - is that intentional?Ĭan you clarify exactly what the repeating column numbers are in the csv data? The first column being column 1. Cell(1, 2) is row 1, column 2 in the table.
Cell(1, 1) is row 1, column 1 in the table. The Word table rows and columns are indexed starting at 1. csvData(0)(0) is row 1, column 1 in the csv data, csvData(0)(1) is row 1, column 2, csvData(0)(8) is row 1, column 9 (not column 8). Cell(1, 10).Range.Text = csvData(0)(10) 'ItemsThe csv rows and columns are indexed starting at 0. When trying your amended looping bit just for one column (7) it debugs on this line Cell(1, 9).Range.Text = csvData(0)(9) 'Collateral description Cell(1, 8).Range.Text = csvData(0)(8) 'Collateral Type Cell(1, 4).Range.Text = csvData(0)(4) 'Expiry Date and Time Set csvTable = (Range:=Selection.Range, NumRows:=UBound(csvLines), NumColumns:=10, _ DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed) 'Split this row (i+r+1) columns 3 and 4 into multiple rows Cell(1, 4).Range.Text = csvData(0)(4) 'Collateral description Cell(1, 3).Range.Text = csvData(0)(3) 'Collateral type Set csvTable = (Range:=Selection.Range, NumRows:=UBound(csvLines), NumColumns:=4, _ĭefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)
Set csvTextStream = FSO.OpenTextFile(csvFile)ĬsvLines = Split(csvTextStream.ReadAll, vbCrLf) Set FSO = CreateObject("Scripting.FileSystemObject") CsvFile = "C:\folder\path\Your csv data.csv" 'CHANGE THIS