team
Excel.Workbooks.Open[path];
opens only xls files and how to open a csv file? it's the same Excel in essence
Opens your string and SWR, 1000%.
But it is more convenient and better to work with the CWS as with a regular text file, which it essentially is.
Click the record macro.
Click Data - From file - select the required csv file and specify the import parameters.
Stop recording and open the macro for editing. We see:
With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\test.csv", Destination _ :=Range("$A$1")) .CommandType = 0 .Name = "test" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 1252 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = True .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With
Such a macro in my Excel 2013 does not reproduce giving an error (which is not surprising for small-scale ones). Delete row
.CommandType = 0
and everything is playing normally.
Source: https://ru.stackoverflow.com/questions/206750/
All Articles