+ Reply to Thread
Results 1 to 3 of 3

String to Object in Userform

  1. #1
    Registered User
    Join Date
    04-29-2012
    Location
    Juperos Elevator
    MS-Off Ver
    Excel 2007
    Posts
    10

    String to Object in Userform

    Hello!
    I am trying to create an animation using the sleep function in vba.
    In my userform, it is initialized that the visibility of the image (named Water1) I want to animate is set to false. (Water1.visible=false)

    After a certain condition is met, I want it to become visible. I have a sheet full of moves, and their corresponding animation (example, Water1). I used vlookup:

    Application.WorksheetFunction.VLookup(Attack1.Caption, Sheet2.Range("a1:b12"), 2, 0).Visible = True

    and the
    Application.WorksheetFunction.VLookup(Attack1.Caption, Sheet2.Range("a1:b12")
    part returns the string "Water1", which is the name of the image.

    When I run the program, the error "object required" appears.

    How can I turn this string into the object (image) of the same name and set its properties (visible)?

    Thank you very much! :D

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: String to Object in Userform

    If the object is a contol type object on the user form, try something like this...

    Dim strObj As String
    strObj = Application.WorksheetFunction.VLookup(Attack1.Caption, Sheet2.Range("a1:b12"), 2, 0)
    Me.Controls(strObj).Visible = True


    It uses the Controls collection to reference a control by name (string).

  3. #3
    Registered User
    Join Date
    04-29-2012
    Location
    Juperos Elevator
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: String to Object in Userform

    Oh, I see. It worked perfectly! Thank you AlphaFrog! :D

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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