+ Reply to Thread
Results 1 to 8 of 8

Define global worksheet name for a userform

  1. #1
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,406

    Define global worksheet name for a userform

    I use worksheet name on several places, and I want to have it only on one place...

    I've tried:
    Please Login or Register  to view this content.
    But it give me

    Compile error:
    Invalid outside procedure


    on Set part of the code...

    What am I missing...
    How can I define Worksheet name only on one place for whole Userform?
    Last edited by zbor; 05-22-2012 at 04:36 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Define global worksheet name for a userform

    Hi

    Try like this:

    Please Login or Register  to view this content.
    Click *, if my suggestion helps you. Have a good day!!

  3. #3
    Forum Guru
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Define global worksheet name for a userform

    hi zbor, if that concerns a userform, you can use

    Please Login or Register  to view this content.
    in userform initializing code that fires first and your public variable will hold sheet object for the use by other private subroutines within userform code level

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,406

    Re: Define global worksheet name for a userform

    thx watersev.. I've tried that first time but somehow failed...

    jraj1106, that's something I could use .. It's working and I can call that macro whenver I need that (I've also defined some other things within a Sub)

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Define global worksheet name for a userform

    In the userform module:

    Please Login or Register  to view this content.
    But I think it's hardly worth while to use a variable that doesn't vary.
    I'd prefer to refer to the sheet in the code using With ... End With

    Please Login or Register  to view this content.
    Last edited by snb; 05-22-2012 at 05:18 AM.



  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,406

    Re: Define global worksheet name for a userform

    Mine case was that Worksheets("TEST") appeared in several private Subs of the same userform so I wanted to define it globaly (for that userform).

    Will defining sheet just in userform_Initialize affect only that Sub or all (like for example Private Sub CommandButton3_Click() )?

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Define global worksheet name for a userform

    Will defining sheet just in userform_Initialize affect only that Sub or all (like for example Private Sub CommandButton3_Click() )?
    It will take effect for the whole userform and all procedures/functions it contains.

    Make a distinction between the scope of the Variable (in this case 'Private') which will suffice for all the code in the 'private' userform, and the point where a value will be attributed to that variable. The scope of the variable is crucial for it's scope, not the point of attributing.

  8. #8
    Registered User
    Join Date
    05-17-2012
    Location
    Dont Know
    MS-Off Ver
    2007
    Posts
    4

    Re: Define global worksheet name for a userform

    Got some good notes.

+ 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