+ Reply to Thread
Results 1 to 4 of 4

VBA workbook reference

  1. #1
    Forum Contributor
    Join Date
    12-14-2012
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    143

    VBA workbook reference

    I have this code that works but the name of the workbook name changes each week. I currently have to go in and change the part W2 to W3
    Each week the number will be different.
    My question is how do I reference this workbook(Work PTS P6W2.xlsm) without referencing the exact workbook name?

    Please Login or Register  to view this content.

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

    Re: VBA workbook reference

    Simple way is to either have the code open the workbook, or pop up a form with a list of open workbooks on it.

  3. #3
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: VBA workbook reference

    I would avoid the .Activate method in most applications but that is besides the point of your question (most solutions that do not require .Activate would need the name of your workbook).

    If you simply need to reference the workbook in which the code is running in, you can easily do that using: ThisWorkbook.Name (that will return a string, including the extension: .xlsm).

    If you need to reference a workbook other than what the code is running in, that may be done using a set of workbooks that are open (given some assumptions on the name and a few If statements using Instr(...).
    If you need to reference a workbook using its directory location, that can easily be done as well.
    <---If my answer helped, please click *

  4. #4
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: VBA workbook reference

    ...Note that if you must use .Activate with the workbook that is open, its name is not required. It may be done using command: ThisWorkbook.Activate

+ 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. Replies: 0
    Last Post: 07-21-2015, 02:35 AM
  2. Replies: 5
    Last Post: 06-17-2014, 10:16 AM
  3. [SOLVED] Locked formula changes reference when rows added to reference sheet in same workbook
    By macrorookie in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-19-2014, 04:08 PM
  4. Replies: 4
    Last Post: 12-01-2013, 03:22 AM
  5. [SOLVED] copy active sheet, create new workbook, name new workbook based on cell reference
    By jm0392 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2012, 07:12 PM
  6. Replies: 2
    Last Post: 05-01-2009, 07:06 PM
  7. [SOLVED] Column Reference-How do I reference a cell in a different workbook?
    By RMD at JMU in forum Excel General
    Replies: 1
    Last Post: 02-03-2006, 12:00 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