+ Reply to Thread
Results 1 to 3 of 3

What's correct syntax for referencing a sheet by Codename?

  1. #1
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 2007
    Posts
    200

    What's correct syntax for referencing a sheet by Codename?

    I've been giving "real" codenames to the sheets in my workbooks, making it easier and clearer to refer to them in VBA code. For example, if I have a sheet named "Raw Data", I will change the codename from Sheet1 (or whatever) to "RawDataSheet". Then I can write VBA code like:
    Please Login or Register  to view this content.
    My problem: What if I start dealing with multiple open workbooks, where I have to start using ActiveWorkbook or ThisWorkbook in the code? I can refer to this sheet as:
    Please Login or Register  to view this content.
    But what if I want to use the codename? Would it be:
    Please Login or Register  to view this content.
    How do I qualify a sheet's codename for a particular workbook?
    Thanks...

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: What's correct syntax for referencing a sheet by Codename?

    Referring to a worksheet by it's codename implies that it is in the workbook where the code resides so ThisWorkBook isn't really necessary.
    I might be proven wrong but as far as I know there is no direct way to refer to a worksheetcodename in other workbook unless you loop through them and checking codenames.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,464

    Re: What's correct syntax for referencing a sheet by Codename?

    Merf

    Why do you want to make it so complicated using CodeName under such situation?
    example
    Please Login or Register  to view this content.

+ 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] Correct syntax for referencing a separate worksheet in a formula when.
    By moosetales in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-20-2014, 03:01 PM
  2. [SOLVED] Referencing sheet codename instead of sheet name not working
    By jshaw82 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-06-2013, 05:25 AM
  3. Referencing a workbook with Codename in a variable.
    By foxguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2012, 08:46 PM
  4. Referencing a sheet's codename
    By LAF in forum Excel General
    Replies: 8
    Last Post: 09-18-2009, 10:00 AM
  5. What is the syntax for referencing another sheet with 'lookup'
    By ihenderson in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-31-2006, 07:08 AM
  6. Referencing worksheet CODENAME in a chart object.
    By Bing in forum Excel General
    Replies: 2
    Last Post: 02-14-2005, 09:06 PM
  7. Referencing worksheet CODENAME in a chart object.
    By Bing in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2005, 04:06 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