Avatar of maverick0728
maverick0728Flag for United States of America

asked on 

Convert 1page PDF to JPG and then insert to Excel

I have 1 page PDF files.  I need to convert them to a JPG or PNG file and then insert the image into Excel.  The PDF files are drawings and we want to display them in the Excel file.  After the excel file closes, I can delete the JPG or PNG file.  I haven't been able to get the PDF file to display as an image in Excel, so I'm thinking I need to convert the PDF to a JPG or PNG in order for them to show as an image.  I don't want to use Adobe professional to convert the PDF files.

Unless there is a way to display the 1 page PDF as an image?
Microsoft ExcelVB Script

Avatar of undefined
Last Comment
Rgonzo1971
Avatar of Rgonzo1971
Rgonzo1971

HI,

You can copy the pdf already inserted in excel and paste it as image and delete the pdf of the excel

Regards
Avatar of maverick0728
maverick0728
Flag of United States of America image

ASKER

Copy and paste of the PDF as a image doesn't work.

I have this code to copy in a PDF, but I receive "This image cannot currently be displayed".
Sub TestInsertPictureInRange()
    InsertPictureInRange "C:\Drawings\test.pdf", _
        Range("A79:J87")
End Sub

Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
    ' inserts a picture and resizes it to fit the TargetCells range
    Dim p As Object, t As Double, l As Double, w As Double, h As Double
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
    If Dir(PictureFileName) = "" Then Exit Sub
    ' import picture
    Set p = ActiveSheet.Pictures.Insert(PictureFileName)
    ' determine positions
    With TargetCells
        t = .Top
        l = .Left
        w = .Offset(0, .Columns.Count).Left - .Left
        h = .Offset(.Rows.Count, 0).Top - .Top
    End With
    ' position picture
    With p
        .Top = t
        .Left = l
        .Width = w
        .Height = h
    End With
    Set p = Nothing
End Sub

Open in new window

SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of maverick0728
maverick0728
Flag of United States of America image

ASKER

That is better - shows a temporary name of the pdf  User generated image
I actually want to show an image of the PDF file contents.  Can this be done?
User generated image
Avatar of Rgonzo1971
Rgonzo1971

and what is "c:\Drawings\test.pdf"

shouldn't be an icon since
 DisplayAsIcon:=False
Avatar of maverick0728
maverick0728
Flag of United States of America image

ASKER

"c:\Drawings\test.pdf" is a pdf with this image:
User generated image
Avatar of Rgonzo1971
Rgonzo1971

if you run it step by step what is the result at line 14
Avatar of maverick0728
maverick0728
Flag of United States of America image

ASKER

line 14 result is:
User generated image
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of maverick0728
maverick0728
Flag of United States of America image

ASKER

Could be.  We are using PDF-XChange.  Can it work with PDF-XChange?
Avatar of Rgonzo1971
Rgonzo1971

No experience with it but maybe by changing temporarily the default program to acrobat reader it could work
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo