VBA insert picture as fill

Rock_Doctor

New Member
Joined
Mar 10, 2017
Messages
14
So I have an excel sheet with formatted shapes with which I use fill to populate the shapes with pictures for a report.

I have the basic macro code sorted to do this with a button but when I try to substitute the file path with a cell on the spreadsheet containing the file path it results in a fill object fail.

Here is the code that works:

Code:
Sub Macro1()'
' Macro1 Macro


' 
    ActiveSheet.Shapes.Range(Array("Rectangle 10")).Select
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .UserPicture _
        "Filepath"
        .TextureTile = msoFalse
        .RotateWithObject = msoTrue
        
    End With
End Sub


After trying to insert the cell value:

Code:
Sub Macro1()'
' Macro1 Macro


'
    PictureFileName = Range("V11").Value
    
    ActiveSheet.Shapes.Range(Array("Rectangle 10")).Select
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .UserPicture _
        PictureFileName
        .TextureTile = msoFalse
        .RotateWithObject = msoTrue
        
    End With
End Sub

I have tried adding quotations in the cell value as well thinking that was the issue.

Any help is much appreciated!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
This worked for me:

Code:
Sub Macro1()
With ActiveSheet.Shapes("rectangle 10").Fill
    .Visible = msoTrue
    .UserPicture CStr([j53])                    ' cell J53
    .TextureTile = msoFalse
    .RotateWithObject = msoTrue
End With
End Sub
 
Upvote 0
I am trying the same thing, and upon trying Worfs sollution I keep getting "Method 'UserPicture' of object 'FileFormat' failed."
Any ideas?
 
Upvote 0

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

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