+ Reply to Thread
Results 1 to 4 of 4

Export sheet to CSV then resave workbook

  1. #1
    Registered User
    Join Date
    07-14-2010
    Location
    Louisiana, US
    MS-Off Ver
    Excel 2007
    Posts
    2

    Export sheet to CSV then resave workbook

    I have quite an interesting problem. I have an XLSM spreadsheet with an Auto_Open macro that imports data from a CSV file and does some deletion/formatting. It then saves that sheet back over the existing CSV file. I then want to resave the workbook over the existing XLSM file. If Excel 2007 is closed before the macro runs, I get "Runtime error '1004': Cannot access 'Computer Name Listing.xlsm'". However, if I run the Auto_Open macro with the workbook already open, the problem does not happen. Any ideas? The problematic section of my code is below.

    Please Login or Register  to view this content.
    If I enter debugging mode, the error line is the ".SaveAs Filename..." line.

    Thanks for your help.
    Last edited by bossier330; 07-14-2010 at 12:16 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Export sheet to CSV then resave workbook

    Use this approach instead to copy the sheet to a new workbook, save the CSV file and close it. It avoids you making any actual changes in the original workbook. After the new workbook closes you are back in your original file and you can save the activeworkbook normally after that if you wish.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

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

    Re: Export sheet to CSV then resave workbook

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-14-2010
    Location
    Louisiana, US
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Export sheet to CSV then resave workbook

    That did it. Thanks for the quick help.

+ 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