Add picture to shape

jeffreybrown

Well-known Member
Joined
Jul 28, 2004
Messages
5,152
This code is working fine; however, can't seem to find how to get the picture to come from inside the workbook instead of a location on the computer?

I embedded the pictures within the workbook and the names are "Picture 3" and "Picture 4".

Also, realize you shouldn't use Select/Selection but can't seem to get away from it here.

Any thoughts?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Rng As Range
    Set Rng = Target.Parent.Range("A1")
    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, Rng) Is Nothing Then Exit Sub
    
    ActiveSheet.Shapes("Rec").Select

    Select Case Target.Value

    Case "Pic1"

        Selection.ShapeRange.Fill.UserPicture "C:\Users\Jeff\Desktop\Pic1.png"

    Case "Pic2"

        Selection.ShapeRange.Fill.UserPicture "C:\Users\Jeff\Desktop\Pic2.png"

    End Select
    
    Application.Goto [A1]
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
If you drag all the your pictures from the sheet to within the shape, then "Group" all the Pictures and the shape together, then by running this code (modified to suit) you can hide all the Pictures except the one you want to show.
Code:
[COLOR="Navy"]Sub[/COLOR] MG07May07
Private [COLOR="Navy"]Sub[/COLOR] CommandButton2_Click()
[COLOR="Navy"]Dim[/COLOR] oShape [COLOR="Navy"]As[/COLOR] Shape, s [COLOR="Navy"]As[/COLOR] Shape
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] oShape [COLOR="Navy"]In[/COLOR] ActiveSheet.Shapes
    [COLOR="Navy"]If[/COLOR] oShape.Type = msoGroup [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] s [COLOR="Navy"]In[/COLOR] oShape.GroupItems
          [COLOR="Navy"]If[/COLOR] Left(s.Name, 7) = "Picture" [COLOR="Navy"]Then[/COLOR] s.Visible = False
          [COLOR="Navy"]If[/COLOR] s.Name = "Picture 3" [COLOR="Navy"]Then[/COLOR] s.Visible = True
        [COLOR="Navy"]Next[/COLOR] s
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] oShape
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Here's a shorter verson , you may be able to use.!!!
Code:
[COLOR="Navy"]Sub[/COLOR] MG07May14
[COLOR="Navy"]Dim[/COLOR] shp [COLOR="Navy"]As[/COLOR] Shape
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] shp [COLOR="Navy"]In[/COLOR] ActiveSheet.Shapes("Group 15").GroupItems
MsgBox shp.Name
[COLOR="Navy"]Next[/COLOR] shp
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top