+ Reply to Thread
Results 1 to 2 of 2

Adding Pictures or Images to Userform with Onchange Event

Hybrid View

ptmuldoon Adding Pictures or Images to... 06-15-2015, 08:25 PM
Norie Re: Adding Pictures or ... 06-15-2015, 08:29 PM
  1. #1
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    863

    Adding Pictures or Images to Userform with Onchange Event

    I'm experimenting with a userform and change event and was wondering how you can add the ability to show an Image of what was selected, sort of a like an example of the item selected.

    So I've create a userform with 2 Combo box's. The first lists the 'Groups' of Fruits, Animals, Cars. And the second then lists the items for each group. And the below works as expected.

    Now I'm trying to figure how (if possible) to show in the userform an image of what what was selected. So if the user chose Animals, and then cat, they would get small 'example' image in the userform of a cat. Or perhaps provide a 'command button' to launch and open image in separate smaller window or user form?

    This is the basis code thus far in setting up the userform and combo box's. But I'm not sure now on how to proceed.

    I should add that I would probably prefer to include the image within the excel file/macro and believe you can use the Picture Property and to not have the files/images stored elsewhere on the users pc.

    Private Sub ComboBox1_Change()
    
    Dim index As Integer
    index = ComboBox1.ListIndex
    
    ComboBox2.Clear
    
    Select Case index
        Case Is = 0
            'Fruits
            With ComboBox2
                .AddItem "Apple"
                .AddItem "Banana"
                .AddItem "Orange"
            End With
            Me.ComboBox2.Text = Me.ComboBox2.List(0)
        Case Is = 1
        	'Animals
            With ComboBox2
                .AddItem "Dog"
                .AddItem "Cat"
                .AddItem "Mouse"
            End With
            Me.ComboBox2.Text = Me.ComboBox2.List(1)
        Case Is = 2
        	'Cars
            With ComboBox2
                .AddItem "Dodge"
                .AddItem "Ford"
                .AddItem "Chevy"
            End With
            Me.ComboBox2.Text = Me.ComboBox2.List(2)
    End Select
    
    End Sub
    
    Private Sub CommandButton1_Click()
       
        Range("A1").Value = ComboBox2.Value
         
    End Sub
    
    Private Sub CommandButton2_Click()
        Unload UserForm3
    End Sub
    
    Private Sub UserForm_Initialize()
    
    With ComboBox1
        .AddItem "Fruits"
        .AddItem "Animals"
        .AddItem "Cars"
    End With
     Me.ComboBox1.Text = Me.ComboBox1.List(0)
     
    End Sub
    Last edited by ptmuldoon; 06-15-2015 at 08:27 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Adding Pictures or Images to Userform with Onchange Event

    Do you have an image control on the userform?

    Do you have the images you want to display stored somewhere?
    If posting code please use code tags, see here.

+ 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] Trying to play with Pictures/Images...
    By DMcCallister in forum Excel General
    Replies: 3
    Last Post: 08-27-2014, 12:17 PM
  2. [SOLVED] Adding change event to dynamically created option buttons on userform
    By Arkadi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2014, 11:38 AM
  3. Intercept onChange event and handle accordingly
    By jayinthe813 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-15-2012, 12:27 PM
  4. Pictures/Images move and distort
    By mmetzler in forum Excel General
    Replies: 0
    Last Post: 06-28-2007, 10:52 AM
  5. Replies: 2
    Last Post: 07-11-2006, 01:35 PM

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