Forum Discussion

nimishbhuta's avatar
nimishbhuta
Frequent Contributor
6 years ago

Insert PDF file into excel sheet

Hello All, 

 

Scenario : I need to have the PDF document shown in the excel sheet. One way I can do it by taking screenshot of PDF file but then it will show for the first page shown on the screen which is not good approach as I require all the pages in the PDF file. 

 

Another way approach is to insert the PDF file in the excel sheet. Like how we do insert object in excel and select the file name which will show all the pages of PDF file. 

 

In this approach, I need to know how can I insert PDF file in excel sheet using vbscript.

 

Regards,

 

Nimish  

  • Hi nimishbhuta,

     

    The following code adds a pdf file to an Excel file - it works on my computer:

    Sub Test
    
      Set Excel = Sys.OleObject("Excel.Application")
      Excel.Workbooks.Open("<path to your Excel file>")
      
      Set Ws = Excel.ActiveSheet
    
      'Add the pdf file
      Set OLEObj=Ws.OLEObjects.Add(,"<path to your PDF file>",true,false)
      
      'If you want to add the file to a specific place
        With OLEObj
            .Left = Ws.Range("A1").Left
            .Height = Ws.Range("A1").Height
            .Width = Ws.Range("A1").Width
            .Top = Ws.Range("A1").Top
        End With
     
      Excel.Quit
    End Sub

     

    P.S. Sometimes I simply love coding :)