+ Reply to Thread
Results 1 to 4 of 4

Save .txt file to .csv in VBA

  1. #1

    Save .txt file to .csv in VBA

    Hi List,

    User has 4 CSV format files. Since there are extra spaces in the files
    when open them from Excel, they have to open each of them using NotePad
    and delete the extra spaces. They can't do this from CSV file directly.
    If they deleted the extra empty column from Excel, and open it again
    with NotePad, the " " will disappear.

    They want these steps can be handle using a macro, so they don't need
    to manually open each file and delete the spaces.

    What I did:

    I open csv file as input, use trim(string) to get rid of the extra
    spaces. then i write each row to a .txt file.

    if i open the txt file using NotePad then do SaveAs to a csv file. it
    works fine. when user reviewing it from NotePad, they still see " "
    around each field. But my question is, how can I accomplish this step
    using VBA?

    I tried to open the txt file from Excel and save it as .csv file, when
    i open the .csv file from NotePad, all the quotes were gone.

    I have posted my questions for a couple of days, but didn't get any
    answers so far. Please, if anyone has any idea, please let me know.

    Thanks so much.


  2. #2
    JE McGimpsey
    Guest

    Re: Save .txt file to .csv in VBA

    Take a look at

    http://www.mcgimpsey.com/excel/textfiles.html

    I don't see any other posts in these groups on the same subject. You can
    find all of your previous posts at

    http://groups-beta.google.com/groups...authors=lliang
    27%40yahoo.com&as_scoring=d

    If you've posted under another address search the archives using that
    address - it's unusual for a request like this to go unanswered:

    http://groups.google.com/advanced_gr...ugroup=*excel*



    In article <[email protected]>,
    [email protected] wrote:

    > User has 4 CSV format files. Since there are extra spaces in the files
    > when open them from Excel, they have to open each of them using NotePad
    > and delete the extra spaces. They can't do this from CSV file directly.
    > If they deleted the extra empty column from Excel, and open it again
    > with NotePad, the " " will disappear.
    >
    > They want these steps can be handle using a macro, so they don't need
    > to manually open each file and delete the spaces.
    >
    > What I did:
    >
    > I open csv file as input, use trim(string) to get rid of the extra
    > spaces. then i write each row to a .txt file.
    >
    > if i open the txt file using NotePad then do SaveAs to a csv file. it
    > works fine. when user reviewing it from NotePad, they still see " "
    > around each field. But my question is, how can I accomplish this step
    > using VBA?
    >
    > I tried to open the txt file from Excel and save it as .csv file, when
    > i open the .csv file from NotePad, all the quotes were gone.
    >
    > I have posted my questions for a couple of days, but didn't get any
    > answers so far. Please, if anyone has any idea, please let me know.
    >
    > Thanks so much.


  3. #3

    Re: Save .txt file to .csv in VBA

    Thanks for your reply.

    I can finish the steps to create a txt file with quotes around each
    fields. But eventually user needs each file with the extension .csv. So
    I tried to open .txt from Excel then save it to .csv, however, if user
    view the .csv file with notepad, all quotes are gone. But if i open the
    ..txt file from notepad, then do a saveas to a .csv format, then review
    the new .csv file from notepad, i got the result user wants to see -
    quotes with each filed. for example,

    "Name", "Street", "City", "State",

    But how can i make this a macro step for user?

    Please help.

    Thanks.


  4. #4
    Tom Ogilvy
    Guest

    Re: Save .txt file to .csv in VBA

    http://support.microsoft.com/default...b;en-us;291296
    Procedure to export a text file with both comma and quote delimiters in
    Excel

    --
    Regards,
    Tom Ogilvy

    <[email protected]> wrote in message
    news:[email protected]...
    > Thanks for your reply.
    >
    > I can finish the steps to create a txt file with quotes around each
    > fields. But eventually user needs each file with the extension .csv. So
    > I tried to open .txt from Excel then save it to .csv, however, if user
    > view the .csv file with notepad, all quotes are gone. But if i open the
    > .txt file from notepad, then do a saveas to a .csv format, then review
    > the new .csv file from notepad, i got the result user wants to see -
    > quotes with each filed. for example,
    >
    > "Name", "Street", "City", "State",
    >
    > But how can i make this a macro step for user?
    >
    > Please help.
    >
    > Thanks.
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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