Insert Image to shape

MarkOW

New Member
Joined
Jun 26, 2018
Messages
35
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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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