+ Reply to Thread
Results 1 to 4 of 4

Referencing a workbook with Codename in a variable.

  1. #1
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Referencing a workbook with Codename in a variable.

    I want to find a workbook when the CodeName is in a variable.
    If I have the Name in variable sName then

    Workbooks(sName) gives me the workbook.

    So when the CodeName is in a variable sCodeName, how can I reference the workbook that it belongs to?
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Referencing a workbook with Codename in a variable.

    Hi foxguy
    Perhaps this (untested)
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Referencing a workbook with Codename in a variable.

    Hello Foxguy,

    The Code name for an object can only be found by walking the collection of objects the code name belongs to. In Excel there are only 3 collections have CodeName properties:Charts, Workbooks, and Worksheets. The Active workbook's CodeName is always "ThisWorkbook". Worksheet code names are like Sheet1, Sheet2, Sheet3, etc. Here is an example that assigns an object variable to the object with the CodeName in sName.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Referencing a workbook with Codename in a variable.

    Leith;
    Thanks for confirming what I already believed.

+ 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