Quotidien Shaarli

Tous les liens d'un jour sur une page.

October 4, 2016

Vbscript to import csv into excel - Stack Overflow

Excel can be rather particular about what it accepts as "valid CSV". I had to resort to the following on several occasions:

Const vbFormatStandard = 1
Const vbFormatText = 2
Const vbFormatDate = 4

Const xlDelimited = 1
Const xlDoubleQuote = 1

' change according to number/type of the fields in your CSV
dataTypes = Array( Array(1, vbFormatText)
, Array(2, vbFormatStandard)

, Array(3, vbFormatText)
, Array(4, vbFormatDate)

)

Set xl = CreateObject("Excel.Application")
xl.Visible = True

xl.Workbooks.OpenText "input.csv", , , xlDelimited, xlDoubleQuote, False _
, False, True, , , , dataTypes
Set wb = xl.ActiveWorkbook