Get image from worksheet in Excel Userform

I am looking to view an image from a worksheet in an image control in a user form.

This image will change depending on the value in the drop-down list. I inserted (Using: Insert → Pictures) a couple of images in the "Sheet1" of my book and named them "Picture1" and "Picture2".

I created below UserForm:

Form http://im56.gulfup.com/msKyqi.png

And this is the code I'm trying to use to download images from a worksheet, but unfortunately it is not working right now.

Private Sub ComboBox1_Change()

UserForm1.Image1.Picture = LoadPicture(Worksheets("Sheet1").Shapes(ComboBox1.Value))

End Sub

Private Sub UserForm_Initialize()

UserForm1.ComboBox1.Clear
UserForm1.ComboBox1.AddItem "Picture1"
UserForm1.ComboBox1.AddItem "Picture2"

UserForm1.ComboBox1.Value = "Picture1"

UserForm1.Image1.Picture = LoadPicture(Worksheets("Sheet1").Shapes(ComboBox1.Value))

End Sub

Every time I run this code, I get the following error:

Error http://im43.gulfup.com/YoWvTp.png

Please inform.

+4
source share
2

!

UserForm, .

, , , UserForm , .

: http://im88.gulfup.com/Moy8I6.png

" False": http://im88.gulfup.com/sAIQqh.png

, , , : http://im88.gulfup.com/oas0EQ.png

: http://im88.gulfup.com/cIO317.png

( , :

http://im88.gulfup.com/1fOSut.png Move Away http://im88.gulfup.com/Q1fzKd.png

, , :

http://im88.gulfup.com/X1UVRB.png

combobox . , :

    Private Sub ComboBox1_Change()

    ' Image1 is the name of the created picture control
    UserForm3.Controls.Item("Image1").Picture = UserForm3.Controls.Item(UserForm3.ComboBox1.Value).Picture 

    End Sub

    Private Sub UserForm_Initialize()

    UserForm3.ComboBox1.AddItem "Argentina"
    UserForm3.ComboBox1.AddItem "Brazil"
    UserForm3.ComboBox1.AddItem "Chile"

    End Sub

, , :

http://im88.gulfup.com/MSqyHF.png

, , Temp, .

+4

LoadImage() ( ). , , .

, , , , . (), , , , LoadImage().

, , , . (, JPEG), LoadImage(), .

+3

Source: https://habr.com/ru/post/1541830/


All Articles