Other PDF Issues

How to Open a PDF from Excel VBA and Copy Data

Steven ParkerSteven Parker Nov 5, 2026 868 views

Question details

The user needs to open a PDF file via Excel VBA and copy its data into a spreadsheet, but standard commands like Shell, AppActivate, and SendKeys are proving unreliable.

How to Open a PDF from Excel VBA and Copy Its Data
Product
Excel VBA
Device & OS
not provided
Scenario
Automating the extraction of data from a PDF document into an Excel workbook using VBA macros.
Observed behavior
AppActivate and SendKeys fail to reliably focus the PDF window to copy the data, and there is uncertainty regarding which Adobe library references are required.
Before you start

Verify the exact file paths for your PDF viewer executable and target PDF document. Confirm whether you are using a standard PDF reader or a professional PDF editor, as this dictates which automation capabilities are available to VBA.

Solution 1Recommended

Use the Shell Function and Wait Command to Open the PDF

Use the Shell function combined with an application wait timer to reliably launch and activate the PDF window.

While using Shell to launch a PDF reader and AppActivate to bring it to the front is a standard approach, relying on SendKeys to copy data is highly unreliable due to unpredictable window focus shifts. If you just need to open the document reliably, this method works well.

1
Quote the file paths

Ensure both the PDF reader executable path and the target PDF file path are enclosed in double quotes within your VBA code.

2
Execute the Shell command

Use code like `id = Shell("""C:\path\to\AcroRd32.exe"" ""C:\path\to\file.pdf""", vbNormalFocus)` to launch the reader as a variable.

3
Add a wait timer

Insert `Application.Wait Now + TimeValue("0:00:02")` to pause the script, giving the PDF application enough time to load.

4
Activate the application

Execute `AppActivate id` to bring the newly opened PDF window into focus.

Use the Shell Function and Wait Command to Open the PDF
SendKeys Limitation: Activating the window is only half the battle. Do not use SendKeys (like sending ^a or ^c) for critical data extraction, as any background process popping up will steal the keystrokes and break your macro.

Convert PDF to Excel Directly with WPS Office

Instead of writing complex and unreliable VBA scripts to extract data via SendKeys, you can use the built-in PDF to Excel conversion tool in WPS Office. It accurately detects tables and text, migrating your data seamlessly without requiring any code.

  1. 1. Open WPS Office: Launch WPS Office and navigate to the PDF tab.
  2. 2. Select PDF to Excel: Click on 'PDF to Excel' from the toolbar tools menu.
  3. 3. Add your file: Upload the PDF document you want to extract data from.
  4. 4. Convert and save: Click 'Convert'. The extracted data will automatically open in a new spreadsheet, ready for editing and saving in .xlsx format.
Built-in PDF to Excel converter with high layout accuracyEliminates the need for complex VBA macro workaroundsSeamlessly handles scanned PDFs with built-in OCR capabilityFully compatible with Microsoft Excel (.xlsx) file formats
microsoft office alternative - wps office

Frequently Asked Questions

Why does AppActivate fail to focus on my PDF window?

AppActivate fails if the PDF application takes longer to load than the VBA script expects, or if the process ID is not correctly passed. Adding a delay using Application.Wait helps ensure the application is ready before the script tries to focus it.

Which Adobe library reference should I use in Excel VBA?

If you have Adobe Acrobat Pro installed, you typically reference the 'Acrobat' type library. Do not select references randomly; free versions like Acrobat Reader do not expose these automation interfaces, meaning the reference will not help.

Is SendKeys reliable for copying data from other applications?

No, SendKeys is generally considered unreliable. It simply mimics keyboard presses at the OS level, meaning if a user clicks elsewhere or a background task pops up, the keystrokes will be sent to the wrong window, causing data loss or unexpected behavior.

Can I use VBA to extract text from a scanned PDF?

VBA cannot natively extract text from an image or scanned PDF. You must first use an OCR (Optical Character Recognition) tool to convert the scanned images into selectable text before extracting it via automation or conversion tools.