+ Reply to Thread
Results 1 to 9 of 9

Referencing a sheet's codename

  1. #1
    Forum Contributor
    Join Date
    05-19-2004
    Location
    United States
    MS-Off Ver
    Office XP and Office 2003
    Posts
    127

    Question Referencing a sheet's codename

    In the VB editor, I changed my sheet's codename and I'm trying to use code to reference the sheet's codename instead of the worksheet name itself because the user can modify the sheet names in on the sheet tab. In the VB editor, I have ShtTestingData(Sheet1). Instead of using
    Set oWS = ActiveWorkbook.Worksheets("Sheet1")
    , I'm trying to use
    Set oWS = ActiveWorkbook.ShtTestingData
    . However, it is not working. Am I missing something?

    Also, using the same sheet name above, how would I re-write the following using the sheet's codename?
    ThisWorkbook.Worksheets("Sheet1").Range("WorkersName").Value = bciValue
    Last edited by LAF; 09-17-2009 at 09:33 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Referencing a sheet's codename

    If the active workbook is the one in which the code is running, just
    Please Login or Register  to view this content.
    But there's probably no need to do that, e.g.
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    05-19-2004
    Location
    United States
    MS-Off Ver
    Office XP and Office 2003
    Posts
    127

    Re: Referencing a sheet's codename

    What if the active workbook is NOT the one in which the code is running?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Referencing a sheet's codename

    Then I don't believe you can refer to it by CodeName, at least not simply.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Referencing a sheet's codename

    To reference the codename across workbooks you can either loop through the sheets and test codename property or use the VBCompents collection (although this needs the Trust settting enabled).

    Either way you can then wrap it up in a function.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Contributor
    Join Date
    05-19-2004
    Location
    United States
    MS-Off Ver
    Office XP and Office 2003
    Posts
    127

    Re: Referencing a sheet's codename

    What if I have something like the following:

    ThisWorkbook.Worksheets("Offering Summary").Range(RngName).Value = bciValue
    Can I just use the Codename instead of Worksheets("Offering Summary")?

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Referencing a sheet's codename

    If you use the function to return an object reference then

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    05-19-2004
    Location
    United States
    MS-Off Ver
    Office XP and Office 2003
    Posts
    127

    Re: Referencing a sheet's codename

    If you create this function to use the object reference, can this object reference be used anywhere in the code then to replace all instances of Worksheets("MySheet")?

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Referencing a sheet's codename

    Yes, assuming you declare the object at the top of the code module.

+ 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