+ Reply to Thread
Results 1 to 7 of 7

VBA code for opening a file with a variable version number in the file name

  1. #1
    Registered User
    Join Date
    02-10-2012
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2010
    Posts
    24

    VBA code for opening a file with a variable version number in the file name

    I have a file that I save with a new version number each time I make major changes. The file name currently is: "Telephony Equipment Inventory v26 (Summary).xlsm". The "26" is the variable number. Can someone give me the vba code to ensure I open the file with the highest version number?

    Trish

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA code for opening a file with a variable version number in the file name

    Hi Trish,

    Try this:

    Please Login or Register  to view this content.
    Last edited by xladept; 01-30-2014 at 02:17 AM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA code for opening a file with a variable version number in the file name

    Hi Trish,

    Try the following written and tested using Excel 2003:
    Please Login or Register  to view this content.
    Lewis

  4. #4
    Registered User
    Join Date
    02-10-2012
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: VBA code for opening a file with a variable version number in the file name

    xladept, this failed at the "U = Dir()" line of code. I liked this because it was short, but if this won't work, I will give the longer code a try.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA code for opening a file with a variable version number in the file name

    Hi Trish,

    I omitted the backslash

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-10-2012
    Location
    Ottawa, Canada
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: VBA code for opening a file with a variable version number in the file name

    I was unable to get your code to work xladept, so I used Lewis' code. Worked perfectly. Thank you, this will come in very handy again.

    Trish

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA code for opening a file with a variable version number in the file name

    Sorry Trish

+ 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. [SOLVED] Error in code - play music file automatically after opening file
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-15-2013, 10:06 AM
  2. [SOLVED] Code for opening file if match with file name is found
    By cokillerliu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-25-2013, 08:41 PM
  3. Replies: 22
    Last Post: 12-11-2012, 12:43 PM
  4. Replies: 0
    Last Post: 08-03-2009, 01:11 PM
  5. [SOLVED] Opening a file with code without a set file name
    By jenkinspat in forum Excel General
    Replies: 1
    Last Post: 03-04-2005, 07:06 AM

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