+ Reply to Thread
Results 1 to 4 of 4

sheet codename issue

  1. #1
    Registered User
    Join Date
    05-01-2006
    Location
    OH
    MS-Off Ver
    Excel 2013
    Posts
    41

    sheet codename issue

    I declare Sheet4m as string, then...

    Please Login or Register  to view this content.


    If the active sheet is sheet 1, then Sheet4m properly stores "Sheet1," but if sheet 2 is the active sheet, then I get a run time error '9': subscript out of range.

    What is the issue?
    Last edited by elprup; 05-18-2010 at 01:06 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: sheet codename issue

    What happens when you streamline that down to:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-01-2006
    Location
    OH
    MS-Off Ver
    Excel 2013
    Posts
    41

    Re: sheet codename issue

    ...it starts working.

    Thanks.

    I was just coming back on to post my follow up problem-solving observance. I found that my original line would work fine if the macro was in a module on the workbook itself, but it wouldn't work from my personal.xlsb. Taking it down to just ActiveSheet.CodeName as you suggested allowed it to work from personal.xlsb.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: sheet codename issue

    Glad it worked.

    You'll need to keep that in mind anytime you want to transfer any macro into your personal workbook. ThisWorkbook references will never work the way you want in there.

    Anytime you convert a macro to a Personal workbook macro all the logic will need to be reviewed to make sure the action is occurring in either
    1) a generic Activesheet object reference
    2) specifically designated workbook/worksheet references

    The 2nd option is always more work to setup, but your macros will be more bullet-proof.

    Cheers.

+ 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