+ Reply to Thread
Results 1 to 3 of 3

2007 VBA Workbook Referencing

  1. #1
    Registered User
    Join Date
    06-10-2009
    Location
    Lexington, KY
    MS-Off Ver
    Excel/Word/Access 2007
    Posts
    6

    2007 VBA Workbook Referencing

    I've searched for a thread on this but didn't come up with anything. I apologize if there is one.

    I'm a self taught VBA'er so I'm not sure if I'm using the best method. I'm converting my 2003 code to 2007 and the file extensions are giving me fits. Any time I use SaveAs or Open I am including the file extensions. Obviously in 2003 this was easy but now I hate to use all this hard code.

    Examples:
    Workbooks.Open "Z:\My Documents\4 Archive\04 - Original Apps\Excel Qual Test\Current Qualifications.xlsx"
    ActiveWorkbook.SaveAs Filename:=(sDir & "Quals to Load.xlsm")

    What's more, my workbooks now include the extension in the title bar at the top (Current Qualifications.xlsx - Microsoft Excel) and my Workbooks("Current Qualifications").Select isn't working presumably because my workbook is "Current Qualifications.xlsx".

    Is there an easier way to handle file extensions in 2007?

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: 2007 VBA Workbook Referencing

    You don't need to use an extension when doing SaveAs as long as you specify the right fileformat argument. That is pretty much essential in 2007 given the different formats available for workbooks.
    For the Workbooks reference it is better, IMO, to always include the extension, but I would point out that it is almost never necessary to actually select or activate a workbook (or worksheet, range etc.) in order to work with it. If you assign the workbook to a workbook variable, then you can refer to it directly:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    06-10-2009
    Location
    Lexington, KY
    MS-Off Ver
    Excel/Word/Access 2007
    Posts
    6

    Re: 2007 VBA Workbook Referencing

    Thanks! I should have probably been using that method all along.

+ 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