+ Reply to Thread
Results 1 to 23 of 23

Converting from CSV to .xslx and delimiting by semi-colons

  1. #1
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Converting from CSV to .xslx and delimiting by semi-colons

    Hi,

    I am trying to convert all the files in a folder from .csv extension to .xlsx extension. The code provided below accomplishes this:


    Workbooks.Open Filename:= _
    "E:\Zando\Finance\09.02.2012\Accessories 09.03.2012.csv"
    sfilename = "Accessories 09.03.2012.csv"
    Windows(sfilename).Activate
    Application.ActiveWorkbook.SaveAs Filename:=Left(sfilename, Len(sfilename) - 3) & "xls", FileFormat:=xlWorkbookNormal

    However, now the issue is that, although the file is now xlsx it hasn't been delimited. I can't manually delimit each .xlsx document because there are too many.

    Does anyone know how I might do this?

    Thank you

  2. #2
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    What do you mean by "it isn't delimited"? Do you mean the csv file contents when opened all appeared in a single column (eg column A)? That's a problem with the way you are opening the csv file if so

  3. #3
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Sounds like you need to use the Text to Columns function

  4. #4
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Firefly: No the csv file appears as it should if you open it i.e. delimited. But then when I convert it to a .xlsx file using VBA all the data that were in separate columns in the csv file now appear as only one or two columns in the xlsx file

    Russell: Yes, I know the Text to Columns function, but in this particular case I can't use it because I want to open the xlsx file ALREADY delimited i.e. don't want to have to delimit it once its already open

    Thanks

  5. #5
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Open up the VBE and open up the Immediate Window (Ctrl+g) and paste in the following line into it:

    Please Login or Register  to view this content.
    With the cursor somewhere on this line, hit Enter. This will open the csv. Does it open correctly? Please do not assume that it will do so and therefore fail to follow the steps above.

  6. #6
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    No, it doesn't open correctly, I didn't notice that before. Is that why it doesn't save the .xlsx file correctly? What can I do to correct that?

  7. #7
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Try executing this line and if it works correctly, use this in your code:

    Please Login or Register  to view this content.
    If it doesn't open correctly with this, can you confirm that the delimiter is actually a comma (and not a semi-colon)?

    If so, try this:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    The first part doesn't work.

    Its not a comma, its a semicolon, but I'm assuming I just replaced "comma" with "semiColon". I ran it, but it doesn't run, I don't think it recognises the dataType argument. Its throwing "Named argument not found".

    Thanks for your help!

  9. #9
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Mike

    Can you post the line of code you are trying to execute that is returning "Named Argument Not Found"? The line should be:

    Please Login or Register  to view this content.
    Note there is no hyphen in Semicolon

  10. #10
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Ok, I was using underscore, thanks. It ran this time, but still the same problem, its not delimiting the text.

  11. #11
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    One last one to try (I've removed the Local argument from above):

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Nope, still not working.

    Thanks for your help though, really appreciate the effort!

  13. #13
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Post (a part of) the file 'E:\Zando\Finance\09.02.2012\Accessories 09.03.2012.csv' here
    What are your international settings: defaultfieldseparator : comma or semicolon



  14. #14
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Hi, here it is. Each column is properly represented as a column in the csv file, but in the xlsx file they are all compressed into the first two or three columns, separated by semi-colons.

    id_catalog simple config
    61028 17322 1021 LI451AC77ZQG-61028
    61029 17323 1021 LI451AC76ZQH-61029
    61035 17329 1021 LI451AC70ZQN-61035

  15. #15
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Zis iz not a file.....

  16. #16
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    That can be pasted in and then use the text to columns function by fixed width. Your column headers will be sacrificed but should easily be replaced.

  17. #17
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Hahaha! Ok I've uploaded it. The forum wouldn't allow me to upload it as a csv, so just changed the file extension to xlsx, but when you get it you can just change it back to csv.
    Thanks for your help!
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Hahaha! Ok, well I've attached the file now. I've saved it as a .xlsx because it wouldn't allow me to upload a csv, but you can just change the extension once you've downloaded it. Thanks!
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Russell: I definitely would do that, but the problem is that when I open the converted excel document, it hasn't even got all the information in one column. Instead of either being one column or all the columns, there are actually about 3 or 4 columns.

  20. #20
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Please Login or Register  to view this content.

    NB. You can always zip a csv-file and post it, or you could change the extension to txt and post that.
    Last edited by snb; 03-12-2012 at 05:54 AM.

  21. #21
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Hi and thanks for that. Only mentioned it as many are not aware of it and I got so much use out of it for a project. I was thinking of taking it back a step but it's good to see you have the answer.

  22. #22
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Hey snb, thanks so much! That code ran beautifully!

  23. #23
    Registered User
    Join Date
    03-09-2012
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Converting from CSV to .xslx and delimiting by semi-colons

    Also to Russell and everyone else who contributed, thanks so much for your help, its really appreciated!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1