cancel
Showing results for 
Search instead for 
Did you mean: 

Import CSV with data type text and semicolon delimiter

JeroenOosterhol
Level 4
I'm importing a CSV file using a semicolon delimiter, which works successfully. However, I would like to use data type Text during the import, as the data contains "00000" values that are transformed to "0" during import. How can I achieve this? I am trying to use TextFileColumnDataTypes, but I'm not sure how to specify it. Alternatively, I could work with a text to columns if the solution is easier. The code used is: Dim dw, ds, dr, qt As Object Try dw = GetWorkbook(Handle, Workbook) ds = GetWorksheet(Handle, Workbook, Worksheet) dr = ds.Range(Range) qt = ds.QueryTables.Add(Connection:="TEXT;" & Path, Destination:=dr) With qt  .FieldNames = True  .RowNumbers = False  .FillAdjacentFormulas = False  .PreserveFormatting = True  .RefreshOnFileOpen = False  .RefreshStyle = 1 'xlInsertDeleteCells  .SavePassword = False  .SaveData = True  .AdjustColumnWidth = True  .RefreshPeriod = 0  .TextFilePromptOnRefresh = False  .TextFilePlatform = 437  .TextFileStartRow = 1  .TextFileParseType = 1 'xlDelimited  .TextFileTextQualifier = Qualifier  .TextFileConsecutiveDelimiter = False  .TextFileTabDelimiter = False  .TextFileSemicolonDelimiter = True  .TextFileCommaDelimiter = False  .TextFileSpaceDelimiter = False  .TextFileTrailingMinusNumbers = True End With qt.Refresh(False) Success = True Catch e As Exception  Success = False  Message = e.Message Finally  dw = Nothing  ds = Nothing  dr = Nothing  qt = Nothing End Try
12 REPLIES 12

​Thanks! You are a hero Ami, works like charm :D.

A small note, I got an error on the last line: "row = temp;". I just deleted it to test and then the code worked.

------------------------------
Nanne van der Wal
Advisor
EY
Europe/Amsterdam
------------------------------

​This is great but can you somehow set a filformat into the code? I have issues with Æ,Ø and Å. I can get my file out with , delimitator but that can't be used, it need to be a ; delimitator and here I donno if I somehow could set the filformat in also its a utf-8 format I need.

------------------------------
Berit Mogensen
Robotics developer
SE Group Service A/S
Europe/Copenhagen
------------------------------

It actually defaults to UTF-8. You can add another argument after the file path if you want to change the encoding, though. https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.fileio.textfieldparser.-ctor?view=netcore-3.1  I suppose it's possible that BP is doing something to the dataTable internally before it becomes a collection, but that's pure hypothesis.

As for semicolons, those should be accepted with that code snippet.

------------------------------
Ami Barrett
Sr Product Consultant
Blue Prism
Plano, TX
------------------------------