Insert Image to shape

MarkOW

New Member
Joined
Jun 26, 2018
Messages
27
Hi everyone,

Hopefully an easy one for someone to help me with.

Can anyone supply the VBA to insert an image from file into a selected shape this is what the recorder gave me.
I would like the user to be able to choose an image from file and not restrict them to a pre-defined name.

Code:
Sub Stage1a()
'
' Stage1a Macro
'


'
    ActiveSheet.Shapes.Range(Array("Rectangle 27")).Select
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .PresetTextured msoTexturePapyrus
        .TextureTile = msoTrue
        .TextureOffsetX = 0
        .TextureOffsetY = 0
        .TextureHorizontalScale = 1
        .TextureVerticalScale = 1
        .TextureAlignment = msoTextureTopLeft
    End With
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .UserPicture "C:\Users\Pictures\IMG_20180510_102823.jpg"
        .TextureTile = msoFalse
    End With
End Sub

Many thanks
Mark

(Excel 2013)
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,515
Office Version
  1. 365
Platform
  1. Windows
See if this works, not tested.
Code:
Sub Stage1a()
'
' Stage1a Macro
'


'
    ActiveSheet.Shapes.Range(Array("Rectangle 27")).Select
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .PresetTextured msoTexturePapyrus
        .TextureTile = msoTrue
        .TextureOffsetX = 0
        .TextureOffsetY = 0
        .TextureHorizontalScale = 1
        .TextureVerticalScale = 1
        .TextureAlignment = msoTextureTopLeft
    End With
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        With Application.FileDialog(msoFileDialogOpen) 
            .AllowMultiSelect = False
            .Show 
            Selection.ShapeRange.Fill.UserPicture .SelectedItems(1) 
         End With
        .TextureTile = msoFalse
    End With
End Sub
If that doesn't work then it may be a case of assigning the file path of the picture to a string variable before starting to work 'With' the shape.
 

MarkOW

New Member
Joined
Jun 26, 2018
Messages
27
Hi jasonb75,

Thanks for the swift reply.

This worked thanks for the help.

Mark
 

Forum statistics

Threads
1,147,748
Messages
5,742,978
Members
423,769
Latest member
LongToast

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
Top