+ Reply to Thread
Results 1 to 10 of 10

Save Single Sheet from multiple sheet workbook as MSDOS CSV format

  1. #1
    Registered User
    Join Date
    08-11-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    15

    Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    I'm very new to VBA and am trying to teach myself through this forum. I'm learning a lot. Unfortunately, I'm stuck on this one. I have a large workbook with multiple sheets. I need a macro to save one of the sheets (ITEMIMPORT) as a new MSDOS CSV format. That file will be used to import data into my company's ERP software & the format has to be MSDOS CSV or the import will not map. I found a script and modified it to come close to what I need but the format is not correct. I get errors when I try to use the file it creates to import into our ERP. I've verified the data is fine by creating a csv file manually and importing into our ERP with the exact same data. That tells me it must be the format created by my script. Below is the script I'm using and attached is an example of my workbook. I appreciate any guidance you can provide!!! Hopefully I learn enough to give back at some point. Best regards...Brett

    Here's the script:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by BBen; 10-10-2012 at 03:38 PM.

  2. #2
    Registered User
    Join Date
    08-11-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    Sorry for the error posting my code. Should be formatted correctly now. Thanks to protonLeaH for the heads up!!!

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    Try this

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  4. #4
    Registered User
    Join Date
    08-11-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    Perfect!!! Worked on the first try. Thanks Mike!

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    Your wecolme

  6. #6
    Registered User
    Join Date
    08-11-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    Thought I was good but am still running into problems. Some of the files work fine, some return odd errors recognizing and mapping the data when I try to import into our ERP. I've noticed two things. If I manually open the csv created by this script and save as MSDOS csv over top of the original, I can import the file w/o errors. I can also open the csv in notepad and save as unicode. Both of those options work but I can't have these extra manual steps at the end. Only other option I know of (but I don't know how to achieve this) is to have all fields wrapped with quotes in the csv file. I was told that would eliminate the random issues we encounter importing the csv files. Don't know if what I described gives any clues to a solution but I greatly appreciate any ideas if you have them. Thanks!!!

  7. #7
    Registered User
    Join Date
    08-11-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    OK, found the issue viewing the file in Notepad. In Notepad, I can see the last row of the csv (appears to be blank in Excel) has a row of commas. When I "save as" over top of the original, that of commas row goes away and the import file works perfectly. So it looks like what I need is to add in the script before it saves a closes, code to delete the last blank row. Is this something reasonable to add?

    Quote Originally Posted by BBen View Post
    Thought I was good but am still running into problems. Some of the files work fine, some return odd errors recognizing and mapping the data when I try to import into our ERP. I've noticed two things. If I manually open the csv created by this script and save as MSDOS csv over top of the original, I can import the file w/o errors. I can also open the csv in notepad and save as unicode. Both of those options work but I can't have these extra manual steps at the end. Only other option I know of (but I don't know how to achieve this) is to have all fields wrapped with quotes in the csv file. I was told that would eliminate the random issues we encounter importing the csv files. Don't know if what I described gives any clues to a solution but I greatly appreciate any ideas if you have them. Thanks!!!

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    See if changing SaveChanges to false instead of true, If that dont work let me know

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-11-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    Hi Mike - I tried that but still same issue. What I did do is take out the .close SaveChanges line so the new file stays open. I then manually deleted the last blank line saved and closed. That gets rid of the last row of extra commas and the file works correctly.

    So it seems to me, if there is a way to add a line of code in your script to find the last blank row and delete the entire row before .close SaveChanges=True I would be good to go. Any thoughts?

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Save Single Sheet from multiple sheet workbook as MSDOS CSV format

    Give this a try

    Please Login or Register  to view this content.

+ 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