Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Using VBA, how do I export Excel file as a CSV?

This is a discussion on Using VBA, how do I export Excel file as a CSV? within the Excel Questions forums, part of the Question Forums category; Using VBA , how do I export Excel file as a CSV file? All help or comments will be appreciated. ...

  1. #1
    Board Regular
    Join Date
    Apr 2002
    Location
    Louisville, Ohio
    Posts
    248

    Default Using VBA, how do I export Excel file as a CSV?

    Using VBA, how do I export Excel file as a CSV file? All help or comments will be appreciated.

    Thanks,

    David

  2. #2
    Board Regular
    Join Date
    Jan 2004
    Location
    Melbourne
    Posts
    3,459

    Default

    I assume by "export", you want to save the file as a CSV. If so update this code:

    ActiveWorkbook.SaveAs Filename:= _
    "c:\MyFile.csv", FileFormat:=xlCSV _
    , CreateBackup:=False

    Regards
    There are three kinds of people - those that can count and those that can't.

  3. #3
    Board Regular
    Join Date
    Apr 2002
    Location
    Louisville, Ohio
    Posts
    248

    Default Re: Using VBA, how do I export Excel file as a CSV?

    tactps,


    That works really good.

    Thanks for your help.

    David

  4. #4
    Board Regular
    Join Date
    Feb 2003
    Posts
    88

    Default Re: Using VBA, how do I export Excel file as a CSV?

    I'm assuming the process would be the same if you wanted to go the other way: a CSV file to an XLS file. I tried this to no avail:

    ActiveWorkbook.SaveAs Filename:= _
    "c:\MyFile.xls", FileFormat:=xlXLS _
    , CreateBackup:=False

    I wasn't sure on what the FileFormat would be named, I think that's where my problem lies. Any ideas?

    Thank you.

  5. #5
    Board Regular
    Join Date
    Jan 2004
    Location
    Melbourne
    Posts
    3,459

    Default

    FileFormat:= _
    xlNormal

    Silly of people to think that there would be any logic in file extentions! lol

    Note - laughing at Excel, not you
    There are three kinds of people - those that can count and those that can't.

  6. #6
    New Member
    Join Date
    Sep 2009
    Posts
    35

    Default Re: Using VBA, how do I export Excel file as a CSV?

    Hello guys,

    When I automate a process to save an excel file to a csv the resulting csv has not Its data formatted into different columns (how I want it) but delimited with commas.

    If I do the process I coded manually (by "saving as") It prompts me a message saying something that I may los some data but It does what I want... If I record that into a macro I get the usual code that you are discussing here, that doesn't do what I want

    Any ideas?

  7. #7
    New Member
    Join Date
    Mar 2010
    Posts
    11

    Default Re: Using VBA, how do I export Excel file as a CSV?

    I have a similar problem. When I manually save an xls file into CSV, the date format is maintained, when I use the same macro code, dd/mm/yyyy is changed to mm/dd/yyyy which I cannot use.

    Any suggestions?

  8. #8
    MrExcel MVP
    Moderator
    Rediscovering the love
    Richard Schollar's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    23,673

    Default Re: Using VBA, how do I export Excel file as a CSV?

    Hi

    I wrote a couple of functions to export ranges of text to new text files (including csv files) which avoids this problem - see post #18 in the following thread for a demonstration of these:

    csv changes date format, help please
    Richard Schollar

    Using xl2013

  9. #9
    New Member
    Join Date
    Mar 2010
    Posts
    11

    Default Re: Using VBA, how do I export Excel file as a CSV?

    Thank you,

    I'm moving jobs soon and there aren't allot of people who would understand that code if it broke. My crude but effective solution for now is to change the date format from 01/06/2010 to 01.06.2010. Seems to work.

    Thanks for the help.

    Stephen

  10. #10
    New Member
    Join Date
    Jul 2010
    Posts
    3

    Default Re: Using VBA, how do I export Excel file as a CSV?

    this csv file can be saved as Utf-8 ?

Page 1 of 2 12 LastLast

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com