+ Reply to Thread
Results 1 to 10 of 10

Referencing Sheet Code name

  1. #1
    Registered User
    Join Date
    10-11-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    45

    Referencing Sheet Code name

    Hi All,

    I have a regular excel extract that im obtaining, however the sheet name is never the same, it is a reference of the system run number "report1442310827144"

    Im wanting to reference the sheet and from what i have seen in forums is that you can use the sheet code name. In this case it is "sheet1".

    However when i go to reference the sheet code name, i seem to have an issue

    My original code is below:-

    Please Login or Register  to view this content.
    Any help would be greatly appreciated!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Referencing Sheet Code name

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-11-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Referencing Sheet Code name

    Quote Originally Posted by TMS View Post
    Please Login or Register  to view this content.

    Regards, TMS
    Thanks TMS, however when i run the code and replace the Worksheets("report1442310827144") with sheet1.codename i get an error message '438' Object doesnt support this property or method.

    Is there something i am doing wrong?

    Cheers,
    RJNC

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Referencing Sheet Code name

    Please Login or Register  to view this content.

    It all depends what you know about the structure of the workbook and what the sheet names, and code names might be.

    You can loop through the sheets to determine what sheet names are present. For example:

    Please Login or Register  to view this content.

    Regards, TMS

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Referencing Sheet Code name

    The code must also be in the same workbook to use the codename directly, or you must set a reference to the target workbook from the code workbook. You can also loop through all the sheets and check the codename form another workbook.
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    10-11-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Referencing Sheet Code name

    Quote Originally Posted by romperstomper View Post
    The code must also be in the same workbook to use the codename directly, or you must set a reference to the target workbook from the code workbook. You can also loop through all the sheets and check the codename form another workbook.
    Thanks reomperstomper, that is the issue then, im referencing a workbook that i require the codename from, is it achievable then? This is my full code.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-11-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Referencing Sheet Code name

    Quote Originally Posted by TMS View Post
    Please Login or Register  to view this content.

    It all depends what you know about the structure of the workbook and what the sheet names, and code names might be.

    You can loop through the sheets to determine what sheet names are present. For example:

    Please Login or Register  to view this content.

    Regards, TMS
    Thanks TMS for your help on this one, the full code is below apologies it would have probably been easier to do that at the get go to understand the structure. I am referencing a sheet in another workbook. Again any help would be really appreciated, I just cant seem to get it right.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Referencing Sheet Code name

    What is the structure of the workbook you are opening? How many worksheets are there? If it's just one, you can use Sheets(1) without needing to refer to the sheet name or sheet code name. If there's more than one, you can loop through them checking the sheet name, or part of the sheet name. What does the sheet name look like? Is there any part uniquely identifiable?

  9. #9
    Registered User
    Join Date
    10-11-2012
    Location
    london
    MS-Off Ver
    Excel 2007
    Posts
    45

    Re: Referencing Sheet Code name

    Quote Originally Posted by TMS View Post
    What is the structure of the workbook you are opening? How many worksheets are there? If it's just one, you can use Sheets(1) without needing to refer to the sheet name or sheet code name. If there's more than one, you can loop through them checking the sheet name, or part of the sheet name. What does the sheet name look like? Is there any part uniquely identifiable?
    Perfect! Thanks for the solution and the assistance TMS, works well.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Referencing Sheet Code name

    You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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: 01-09-2013, 06:58 AM
  2. Referencing original sheet to copy/paste into new sheet without using file name
    By pgarakani in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2012, 02:06 PM
  3. Replies: 5
    Last Post: 03-14-2012, 12:42 PM
  4. Optimizing the Vlookup code in VB. Repitive code with different referencing range.
    By raknahs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2010, 05:03 PM
  5. referencing different sheet in code
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-11-2008, 11:29 AM
  6. Replies: 8
    Last Post: 02-03-2007, 01:41 AM
  7. [SOLVED] Referencing code outside of current sheet
    By nemadrias in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2006, 03:30 PM
  8. referencing a sheet named in a cell then using data from that sheet
    By gbeard in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-15-2005, 04:06 AM

Tags for this Thread

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