How to open & select PDF data and paste it in excel file using VBA code ?

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
this will copy and paste the selected page of your pdf file into the first cell in the open worksheet, then close the pdf after the copy and paste.. There are also two sections of code that ensure the button remains in the same location and the same size.

Code:
Private Sub CommandButton1_Click()
   
    'In order to use the macro you must enable the Acrobat library from VBA editor:
    'Go to Tools -> References -> Adobe Acrobat xx.0 Type Library, where xx depends
    'on your Acrobat Professional version (i.e. 9.0 or 10.0) you have installed to your PC.
    
    Dim PDFApp As AcroApp
    Dim PDFDoc As AcroAVDoc
    Dim PDFPageView As AcroAVPageView
    Dim PDFPath As String
    Dim DisplayPage As Integer
    
   'regulate button location
        Set btn = ActiveSheet.Shapes("CommandButton1")
With btn
 btLeft = .Left
    btTop = .Top
    End With
    
    'find the PDF file in your documents
        PDFPath = "your pdf path.pdf"

    
    'Set the page you want to be displayed
    DisplayPage = 1
    
    'Initialize Acrobat by creating App object
    Set PDFApp = CreateObject("AcroExch.App")
    
    'Set AVDoc object
    Set PDFDoc = CreateObject("AcroExch.AVDoc")
    
    'Open the PDF
    If PDFDoc.Open(PDFPath, "") = True Then
        PDFDoc.BringToFront
        
        'Maximize the document
        Call PDFDoc.Maximize(True)
        
        Set PDFPageView = PDFDoc.GetAVPageView()
        
        'Go to the desired page
        'The first page is 0
        Call PDFPageView.GoTo(DisplayPage - 1)
        
        'Select All Data In The PDF File's Active Page
SendKeys ("^a"), True

'Right-Click Mouse
SendKeys ("+{F10}"), True

'Copy Data As Table
SendKeys ("c"), True

'Minimize Adobe Window
SendKeys ("%n"), True

'Select First Cell
Range("A1").Select

'Paste Data In This Workbook's Worksheet
ActiveSheet.Paste
        
        '-------------
        'ZOOM options
        '-------------
        '0 = AVZoomNoVary
        '1 = AVZoomFitPage
        '2 = AVZoomFitWidth
        '3 = AVZoomFitHeight
        '4 = AVZoomFitVisibleWidth
        '5 = AVZoomPreferred
        
        'Set the page view of the pdf
        Call PDFPageView.ZoomTo(2, 50)
        
    
    End If

    Set PDFApp = Nothing
    Set PDFDoc = Nothing
    
    'Maximize Adobe Window
SendKeys ("%x")


'Close Adobe File and Window
SendKeys ("^w"), True
    
'Select First Cell
Range("A1").Select
    
'regulate button size
CommandButton1.Height = 35
CommandButton1.Width = 125

    On Error Resume Next
   
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,664
Members
449,114
Latest member
aides

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