Need help on Insert PDF file VBA function

spycein

Board Regular
Joined
Mar 8, 2014
Messages
135
Office Version
  1. 365
Platform
  1. Windows
Dear Members,

I am using the following code to display photo from a folder in my excel sheet.

VBA Code:
Sub DisplayMainPicture()
With Sheet1
On Error Resume Next
.Shapes("ReceiptPic").Delete
On Error GoTo 0
If .Range("I12").Value = Empty Then Exit Sub
PicPath = .Range("I12").Value  'Picture Path
If Dir(.Range("I12").Value, vbDirectory) = "" Then Exit Sub  'Exit on missing or incorrect file
On Error GoTo NoPic
With .Pictures.Insert(PicPath)
            With .ShapeRange
                .LockAspectRatio = msoTrue
                .Height = 350
                .Name = "ReceiptPic"
            End With
End With
    With .Shapes("ReceiptPic")
        .Left = Sheet1.Range("K4").Left
        .Top = Sheet1.Range("K4").Top
    End With
NoPic:
End With
End Sub

If I put a pdf file in the folder and try to fetch the image then I get " The picture cannot be displayed" error message.
I am looking for a solution which would show both images as well as PDF files.
Thank you so much.
Best Regards,
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Maybe you've outgrown Excel for what you're trying to do. Access has bound and unbound object controls which will show documents. Possibly will show pictures as well, but there is an image control for that in Access. I see no object control in the userform controls toolbox so I think you're not going to solve this with Excel.
 
Upvote 0
Maybe you've outgrown Excel for what you're trying to do. Access has bound and unbound object controls which will show documents. Possibly will show pictures as well, but there is an image control for that in Access. I see no object control in the userform controls toolbox so I think you're not going to solve this with Excel.
Dear @Micron, Thank you so much for your feedback on this.
Best Regards,
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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