1

I have a CSV file filename.csv with the following content:

UID;Datum;Klasse;SendungsNr
6177;14.08.20;624;00340434299338038179
6178;14.08.20;624;00340434299338038186
6179;14.08.20;624;00340434299338038193

As far as I understand (here, here, here for the MS reference, etc. ...) this should import the file an insert the data into different columns:

Public Sub OpenCsvFile()
    filepath = "C:\folder 1\folder 2\filename.csv"
    Workbooks.OpenText Filename:=filepath, DataType:=xlDelimited, Semicolon:=True
    End Sub

But it doesn't (see "update" below - seems to be a problem with the filename), it just uses the A column:

enter image description here

I tried specifying it over the other flag but the result stays the same:

Workbooks.OpenText Filename:=filepath, DataType:=xlDelimited, Other:=True, OtherChar:=";"

Since this can not be that difficult, I guess I'm just "blind" today, where's the problem?

Update: I found out that changing ".csv" to ".txt" seems to do the trick: it opens it into separate columns. Is that a bug or the desired behavior? Did I overlook anything in the MS reference? Now the question is, how do I get it to work without renaming the files (if it can be done at all)?

Update2: The solution, for whatever reason is to use Local:=True as a parameter (see the second link in the duplication notice, and some info is here as well). Why this has anything to do with the file suffix I can not fathom.

14
  • 2
    Record a macro and see what code is generated. Commented Aug 16, 2020 at 9:21
  • @Tarik it uses "Workbooks.Open" (or some other procedures depending on how excatly I open it) which doesn't help me in this case. Commented Aug 16, 2020 at 9:35
  • Your code works as expected with your sample data. In which encoding is your file saved? Commented Aug 16, 2020 at 9:45
  • 1
    @GSerg I ment which did you use to make it work? But never mind, I already found part of the problem (see update addition at the end of my question) Commented Aug 16, 2020 at 9:54
  • 1
    Do you mean changing of "filename.csv" with "filename.txt"? If yes, this only means that your file were/are not csv... Commented Aug 16, 2020 at 10:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.