Consulting

Results 1 to 7 of 7

Thread: VBA userForm: changing images

  1. #1

    Unhappy VBA userForm: changing images

    hello!
    My question will be about images in VBA forms.
    I'm trying to create CHinese horoscope. But there is one thing I cannot manage with....

    I have to change year of birth and everytime I change theyear the picture next to it has to be changed.

    For instance, If I change the year to 1999 then the picture will show RABBIT...and so on...


    Please, help me on this problem as quickly as possible!!!

    Thank you in advance

    P.S. The pictures needed in my work are in my excel workbook, but I still cannot "connect" years to these images.=(((((

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Do you have a copy of the images in a folder? I think that would be easier to work with.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you can load all the images into the userform, one on top of the other; set them to Visible = False. This can make the relevant image visible.
    [vba]
    Private Sub TextBox1_AfterUpdate()
    For i = 1 To 12
    Me.Controls("Image" & i).Visible = False
    Next
    tmp = (CLng(TextBox1) Mod 12)+1
    Me.Controls("Image" & tmp).Visible = True
    End Sub

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    well, if it can help you to understand I attached my excel file

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This is really a workaround
    Save the folder to the C drive. Images for years 2000 - 2002 added.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    thank you, but I cannot make it work...the button doesn't open the form

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Probably a conversion issue, Delete and replace the button.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •