+ Reply to Thread
Results 1 to 7 of 7

incorrect saving due to incompatability in versions

  1. #1
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    incorrect saving due to incompatability in versions

    I have written some VBA in excel 2003 part of the code opens new workbooks and later saves them using the code below:

    Please Login or Register  to view this content.
    then later using:

    Please Login or Register  to view this content.
    when run in 2003 this works fine. However when it is run with office 2010 the saved file is corrupted. Presumably this is because office 2010 is being forced to save files with .xls extension. I could of course change the code to save with .xlsx format but then no doubt it would have problems when run on other machines running 2003.

    So ideally I need a way to cover both. Is there for VBA to return the current version, if so I could change the code to
    If (version 2010) then save as..........etc.

    Or is there a better way?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: incorrect saving due to incompatability in versions

    The SaveAs method includes a FileFormat argument to control the type of file.

    In creating the name, leave off the extension; it will be added to the file name correctly by type.

    Application.Version will tell you what version of Excel you're running.

    Additional FileFormat enumerations were added in 2007 (as you'd expect). Those values are unknown to earlier versions of Excel, so you need to declare them as constants if you ever intend to use the code in earlier versions, so you don't get compile errors.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    Re: incorrect saving due to incompatability in versions

    shg,

    Thanks for the answer. Unfortunately it doesn't quite work.

    I have removed the file extension as you suggested and when run in excel 2003 it does indeed save the files as .xls format. However running it in 2007 caused the files to be saved without any extension

    (I have also noticed that the column width formatting is lost when running in 2007 though I think perhaps I'll post that as a separate topic if I find nothing through a search)

  4. #4
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    Re: incorrect saving due to incompatability in versions

    is there any reason why I can't (or shouldn't) use this:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: incorrect saving due to incompatability in versions

    What did you use for the the FileFormat argument?

  6. #6
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    Re: incorrect saving due to incompatability in versions

    shg,

    I didn't use anything. I'm sorry I must have misunderstood your instructions I thought you meant to leave it out altogether (which is what I did)

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: incorrect saving due to incompatability in versions

    No, I meant you should use it.

+ 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