+ Reply to Thread
Results 1 to 5 of 5

Reference Userform Object dynamically

  1. #1
    Registered User
    Join Date
    09-04-2014
    Location
    WA, USA
    MS-Off Ver
    2007
    Posts
    69

    Reference Userform Object dynamically

    I know how to reference an object on a worksheet in this way using a variable:

    Please Login or Register  to view this content.
    I cannot find the way to do this on a userform. I thought it was something like this:

    Please Login or Register  to view this content.
    Unfortunately, this is not working. I get an error:
    "Could not find the specified object."
    I'm sure there is a way to do this on a userform too. My end goal is to compare the location of two images. I can post my whole code so far, if it helps, but it is an incomplete mess.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Reference Userform Object dynamically

    Your syntax appears to be correct as far as I can tell.

    I suggest you change the code slightly to something like (untested) to make sure the Control Name your are creating is the name of an actual Control:
    Please Login or Register  to view this content.
    Debugger Secrets:
    a. Press 'F8' to single step (goes into subroutines and functions).
    b. Press SHIFT 'F8' to single step OVER subroutines and functions.
    c. Press CTRL 'F8' to stop at the line where the cursor is.
    d. 'Left Click' the margin to the left of a line to set (or clear) a BREAKPOINT.
    e. Press CTRL 'G' to open the IMMEDIATE WINDOW. 'debug.print' statements send their
    output to the IMMEDIATE WINDOW.
    f. Select View > Locals to see all variables while debugging.
    g. To automatically set a BREAKPOINT at a certain location put in the line:
    'Debug.Assert False'
    h. To conditionally set a BREAKPOINT at a certain location put in lines similar to:
    if i >= 20 and xTV20 > 99.56 then
    Debug.Assert False
    endif
    i. A variable value will be displayed by putting the cursor over the variable name.

    Lewis

  3. #3
    Registered User
    Join Date
    09-04-2014
    Location
    WA, USA
    MS-Off Ver
    2007
    Posts
    69

    Re: Reference Userform Object dynamically

    Lewis, I really appreciate your thoughts on the matter! Your suggestion doesn't seem to change anything. Thank you for the debugging tips, I usually use 'msgbox' to help with debugging. I'll look into some of the debugging tools you explained.

    I'll post the code I've got so far.

    Please Login or Register  to view this content.
    Sorry if the code is messy for reading. Again, any help will be greatly appreciated.

  4. #4
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: Reference Userform Object dynamically

    Hello Socrates! Can you upload your file ? (after removing sensible/confidential data of course)

    About the debug.assert there is no need for If, Then, End If. The Debug.Assert command is a conditional breakpoint that will cause execution to pause on the Debug statement if the expression that following the Assert statement is False. For example,

    Debug.Assert Var >= 0

    This will pause on the Debug.Assert statement if Var >= 0 is False; that is, it will pause if Var is negative. More about debugging here.
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  5. #5
    Registered User
    Join Date
    09-04-2014
    Location
    WA, USA
    MS-Off Ver
    2007
    Posts
    69

    Re: Reference Userform Object dynamically

    Excuse me for the double post, but it seems I've solved my own problem. It was a problem with not having the userform ('UserFormPlayerInfo') open during my testing. Therefore, the control could not be located.

    Thanks again for your help Lewis!

    Best regards,
    SocratesJC

    (edit, Thanks Bulina2k.)

+ 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. [SOLVED] Dynamically select List Object name
    By escobf in forum Excel General
    Replies: 14
    Last Post: 05-14-2013, 05:29 PM
  2. [SOLVED] Userform object reference by variable
    By CurbenJ in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-21-2013, 05:41 PM
  3. [SOLVED] Generic Current Object Reference Inside that Object's Code
    By Aegwyn11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-02-2012, 01:23 PM
  4. How to dynamically change inserted object
    By grivage in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-09-2011, 11:53 AM
  5. Dynamically add code for a object using Macro
    By budhaditya in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-31-2010, 01:04 AM

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