+ Reply to Thread
Results 1 to 10 of 10

Saving to a .csv file and only 1st row contains quotes

  1. #1
    Registered User
    Join Date
    08-24-2009
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    6

    Saving to a .csv file and only 1st row contains quotes

    I am trying to create a .csv file from an Excel file using VBA and when I use the ActiveWorkbook.SaveAs command, only the first row of text contains " quotes around the text. I have multiple rows that must contain the quotes. I have tried using """", and Chr(34), but then that puts """ (3 quotes) around my text. Is there a different function that I should be attempting to use? I am using concatanation to create a field where I would like the quoted text and am using the ActiveCell.Value command (ActiveCell.Text didn't seem to make any difference).

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Saving to a .csv file and only 1st row contains quotes

    Hello MOFLBoy,

    Welcome to the Forum!

    It would help to see the code you have written in VBA to this. The best option is to post your workbook for review.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    08-24-2009
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Saving to a .csv file and only 1st row contains quotes

    I have commented out the text in my EndRoutine() subroutine that does the actual file saving. If you need to uncomment it to test, you'll need to use your own path of course.
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Saving to a .csv file and only 1st row contains quotes

    Hello MOFLBoy,

    When I run the code, none of the cells have quotes around them. This is what I would expect to see. Do you want certain cells to quotes around the text?

  5. #5
    Registered User
    Join Date
    08-24-2009
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Saving to a .csv file and only 1st row contains quotes

    Hi Leith,
    Yes, I am wanting the Automatic Summary cell to have quotes at the beginning and end of the 3 line paragraph. My experience has been that even if I use the Chr(34) at the beginning and end, saving it as a .csv file gives me unpredictable results. For Example: If I use Chr(34) at the beginning and end, I will wind up with 3 double quotes """ at the beginning and end. If I don't use Chr(34), the maybe the first row will have quotes, but the subsequent rows won't. I thank you for your diligence in this too very much.
    Bob

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Saving to a .csv file and only 1st row contains quotes

    Hello Bob,

    I know I can put quotes around the text using VBA to create the csv file rather than Excel. I will need some time to amend your macro to do that.

  7. #7
    Registered User
    Join Date
    08-24-2009
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Saving to a .csv file and only 1st row contains quotes

    That would be great Leith! Thanks!

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Saving to a .csv file and only 1st row contains quotes

    Hello MOFLBoy,

    I ran this macro and created a CSV file with the data in column "B" in quotes. The header is excluded. Try this out on a copy of the real data and let me know how it goes.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-24-2009
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Saving to a .csv file and only 1st row contains quotes

    Dear Leith,
    That works great!

    I'm now learning that they are trying to read this file in to VB and saving it as a .csv file is adding additional quotes (I see this when viewing it via notepad).

    Alas, now I'm being asked to not save it as a .csv file but to just write a text file so I guess I'll look into another avenue and a slightly different post after I do some more reading and googling

    Thank you for all your hard work and persistence, I really appreciate it.
    Bob

  10. #10
    Registered User
    Join Date
    08-24-2009
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Saving to a .csv file and only 1st row contains quotes

    Hi Leith,
    I'm sorry I've not responded to this lately. I was able to get better user requirements and have actually settled on the below code to write out the CSV file and hope someone might be able to utilize it. I've not included any error handling routines since it's just a temporary item for us.

    I really appreciate all your time and effort!!

    Bob

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 09-02-2009 at 05:20 PM. Reason: Added Code Tags

+ 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