The sample PDF file (Employee Record) contains the following table.
Method 1 – Using the Object Feature to Attach a PDF File in Excel
Steps:
- Select the cell in which you want the PDF file.
- Go to the Insert tab.
- Select Text.
- In the drop-down menu, select Object.
- In the Object dialog box, select Create from File.
- Choose Browse.
- In Browse, select the PDF file you want to attach.
- Click Insert.
- Check Link to file and Display as icon.
- Click OK.
You have attached the PDF file.
- Right-click the PDF file.
- Select Format Object.
- In the Format Object dialog box, choose Properties.
- Select Move and size with cells.
- Click OK.
- The PDF file will be fixed in this cell. If you resize the cell the file will automatically be resized.
- Open the PDF by double-clicking it.
Read More: [Fixed!] Cannot Insert Object in Excel
Method 2 – Using the Hyperlink Feature in Excel
Steps:
- Select the cell in which you want the PDF file.
- Go to the Insert tab.
- Select Illustrations.
- Choose Pictures.
- In the drop-down menu, select This Device.
- In Insert Picture, select the PDF.
- Click Insert.
The picture is inserted.
- Resize the image by clicking and dragging its corner.
- This is the output.
- Right-click the picture.
- Select Link.
- In the Insert Hyperlink dialog box, select Existing File or Web Page.
- Select the PDF file you want to attach.
- Click OK.
- The link to the file will be inserted into the image. You can see it by hovering the cursor over the picture.
- Click the picture to open the PDF file.
This is the output.
Method 3 – Using VBA to Attach a PDF File
Steps:
- Go to the Developer tab.
- Select Visual Basic.
- In the Visual Basic Editor window, select Insert tab.
- Choose Module.
- Enter the following code in the module.
Sub Attach_PDF_file()
Dim PDF_file As String
PDF_file = Dir("E:\office\Article 68\")
Do While Len(PDF_file) > 0
If Right(PDF_file, 3) = "pdf" Then
ActiveSheet.OLEObjects.Add(Filename:= _
"E:\office\Article 68\" & PDF_file _
, Link:=False, DisplayAsIcon:=False).Select
End If
PDF_file = Dir
Loop
End Sub
Code Breakdown
- A Sub Procedure named Attach_PDF_file is created.
- A variable named PDF_file as String is declared.
- A Do While Loop is used to repeat the loop while the condition is true.
- An If Statement is used to run the code for a specific condition.
- The If Statement is ended.
- The Sub Procedure is ended.
- Save the code and go back to your worksheet.
- Go to the Developer tab.
- Select Macros.
- In the Macro dialog box, select Attach_PDF_file as the Macro name.
- Click Run.
The PDF file is inserted and the first page is displayed.
- Resize the PDF file.
This is the output.
- Double-click the file to open the PDF.
This is the output.
Read More: How to Attach Documents in Excel
How to Copy Data from a PDF File to Excel
Use the Power Query Editor.
Steps:
- Go to the Data tab.
- Select Get Data.
- Select From File.
- Choose From PDF.
- In the Import Data dialog box, select the PDF file.
- Click Import.
- In the Navigator dialog box, select from where you want to get data. Here, Page001.
- Click Transform Data.
- The Power Query Editor will open.
- Click the table button as shown in the following picture.
- Select Use First Row as Headers.
This is the output.
- Click Close & Load.
- Select Close & Load To.
- In Import Data, select Existing Worksheet.
- Choose a location for your data.
- Click OK.
- Data in the PDF file was copied to Excel.
- Format the table.
Read More: How Do I Insert a Multiple Page PDF into Excel
Things to Remember
Whenever working with VBA, save your Excel file as an Excel Macro-Enabled Workbook. Otherwise, VBA will not work.
Practice Section
Practice here.
Download Practice Workbook
Download the practice workbook here.
Related Articles
- How to Insert an Excel File into Another Excel File
- How to Attach Email in Excel
- [Fixed!] Cannot Insert PDF into Excel
- How to Attach Zip File in Excel
- How to Attach Screenshot in Excel
<< Go Back to Attach File in Excel | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!