+ Reply to Thread
Results 1 to 4 of 4

Data Export Macro works in Excel 2013 but not Excel 2007

  1. #1
    Registered User
    Join Date
    05-26-2016
    Location
    USA
    MS-Off Ver
    Multiple
    Posts
    2

    Data Export Macro works in Excel 2013 but not Excel 2007

    I have a macro that creates a new workbook, copies some data from the source book, pastes into the newly created book, then saves that new book and closes it. This code works PERFECTLY in Excel 2013, but does not function in Excel 2007. It breaks on the line indicated in my code below with the 1004 error: Method 'SaveAs' of object '_Workbook' failed

    The code in question:

    Please Login or Register  to view this content.

    My guess is that it has to do with the fact that I have a variable file format, but this is required given that the user needs to be able to save as either a CSV or tab delimited text, depending on the application.

    Like I said, this code runs perfectly in Excel 2013. Some computers at my place of business however use older versions of office, 2007 being common, and this doesn't want to function on those older versions. Any idea how I might be able to modify this code to enable it to run on older versions of Excel (at least as old as 2007) as well?

    Many thanks!

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Data Export Macro works in Excel 2013 but not Excel 2007

    Try testing for which version is being used with

    Please Login or Register  to view this content.
    and have two versions of the saveas line depending on the application version.

    Try recording a saveas in 2007 to get the correct syntax.
    Martin

  3. #3
    Valued Forum Contributor
    Join Date
    01-03-2016
    Location
    Conwy, Wales
    MS-Off Ver
    2016
    Posts
    974

    Re: Data Export Macro works in Excel 2013 but not Excel 2007

    I have not been able to test with 2007.

    I suggest you try using numeric values instead of the names for the file formats. Numeric values are less flaky across versions. And they also work with later versions of Excel.

    Your variable now needs to be numeric not a string
    so
    Please Login or Register  to view this content.
    then
    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    If a response has helped then please consider rating it by clicking on *Add Reputation below the post
    When your issue has been resolved don't forget to mark the thread SOLVED (click Thread Tools at top of thread)

  4. #4
    Registered User
    Join Date
    05-26-2016
    Location
    USA
    MS-Off Ver
    Multiple
    Posts
    2

    Re: Data Export Macro works in Excel 2013 but not Excel 2007

    I'm such an idiot. The problem actually has nothing to do with Excel 2013 vs 2007. The computers that are running Excel 2007 have no user login as they are a shared resource, and the name given to the windows account has a "." in it! That was throwing off the InStr calculation in this step:

    Please Login or Register  to view this content.
    Once I recognized that, simply changing the function from InStr to InStrRev fixed the problem!

    I appreciate all your input though. Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro that works in Excel 2010 does not work in Excel 2013
    By karenmwhaley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2016, 08:12 PM
  2. [SOLVED] Macro to move a row works in excel 2010 but not in Excel 2013
    By mmccra2858 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-31-2015, 05:07 PM
  3. Excel 2007 VBA to Export Sheet as PDF doesn't work in 2013
    By WilliamJones in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2015, 07:28 PM
  4. Excel 2007 works but not 2010 or 2013
    By Miliano in forum Excel General
    Replies: 1
    Last Post: 10-02-2014, 03:20 AM
  5. Replies: 4
    Last Post: 04-10-2014, 12:11 PM
  6. Works in Excel 2007, does not work in 2013
    By froggy50 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2014, 06:42 AM
  7. Replies: 10
    Last Post: 08-20-2013, 01:02 PM

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