+ Reply to Thread
Results 1 to 3 of 3

Accessing objects by name

  1. #1
    Registered User
    Join Date
    03-05-2010
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2003
    Posts
    5

    Accessing objects by name

    I Solved it! - use Me.OLEObjects("OptionButton" & CStr( i)).Visible = False

    I am trying to control the visibility of several buttons using a procedure. I want to specify the buttons by name. The name is dynamically constructed at run time within a for loop. I saw the following code fragment online but cannot get it to work in my Excel macros:

    Please Login or Register  to view this content.
    So the first iteration would have the effect of OptionButton1.Visible = False
    The second iterations would have the effect of OpetionButton2.Visible = False
    And so on.

    Since the code fragment doesn't work, how can I access an object by dynamically constructing its name at run time? Thanks in advance.

    Joe
    Last edited by jdvorak; 03-06-2010 at 12:21 AM.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Accessing objects by name

    jdvorak,

    Welcome to the Forum.
    However, your post does not comply with the Forum Rules which you agreed to follow. Per Rule #3, all VBA code must be wrapped in code tags. Please edit your thread to add the code tags, after which solutions will be suggested.

    Rule #3

    Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button. For more information about these and other tags, click here.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Accessing objects by name

    Thanks for posting back with your solution - this will invariably help others looking to do similar going forward
    (thanks also for adding tags)

+ 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