How to Copy a Selected PDF Paragraph into Word Using VBA
Question details
The user wants to automate the process of selecting a paragraph in a PDF file, copying it using VBA (specifically with the SendKeys method), and pasting it into Microsoft Word while maintaining the original text formatting.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Automating text extraction from a PDF reader into a Word document using a VBA script.
- Observed behavior
- Relying on VBA SendKeys to copy from a PDF is often unreliable because it depends heavily on the active window, the specific PDF reader's interface, and whether the PDF contains editable text or scanned images.
Before attempting to use VBA to copy text, ensure your target PDF contains an editable text layer rather than scanned images, and verify that your default PDF reader allows programmatic text extraction.
Use Dedicated PDF Parsing Libraries Instead of SendKeys
SendKeys is inherently unreliable for copying text because it simulates keystrokes that can easily miss their target. Using an API or dedicated PDF parsing library ensures accurate and reliable text extraction.
The SendKeys method in VBA mimics keyboard inputs (like Ctrl+C). This approach is highly prone to errors if the PDF reader window loses focus, takes too long to load, or if the PDF contains scanned, non-selectable text.
Open your PDF file manually and try to select the target text with your cursor. If you cannot highlight individual words, the document is a scanned image and requires OCR (Optical Character Recognition) processing before any VBA extraction.
Instead of SendKeys, integrate a dedicated PDF library (such as the Adobe Acrobat API or a third-party parsing tool) into your VBA project references to directly read the text stream from the file.
When pasting the extracted text into Word via VBA, use the Selection.PasteAndFormat(wdFormatOriginalFormatting) command to ensure the text attempts to retain its original PDF styling.

Convert the Entire PDF to Word First
If VBA automation is too complex or fails due to PDF reader limitations, converting the PDF directly to a Word document provides a much more robust and format-friendly solution.
Easily Convert and Copy PDF Text with WPS Office
Instead of struggling with complex VBA scripts and unreliable SendKeys commands, you can use WPS Office to directly open PDFs, perform OCR on scanned documents, and convert them seamlessly into editable Word formats.
- 1. Open the PDF: Launch WPS Office and open your target PDF file directly within the application.
- 2. Run OCR (If needed): If the PDF is a scanned image, navigate to the 'Tools' tab and use the built-in OCR feature to recognize and extract the text.
- 3. Convert to Word: Click on 'PDF to Word' under the 'Tools' tab to instantly convert the document into an editable Word file.
- 4. Copy and Edit: Open the newly created Word document in WPS Writer to easily copy, paste, and edit your paragraphs with all original formatting preserved.

Frequently Asked Questions
Why does SendKeys often fail when copying text from a PDF in VBA?
SendKeys simply mimics keyboard inputs like Ctrl+C. If the PDF reader window loses focus, takes a fraction of a second too long to load, or if the text isn't properly highlighted beforehand, the command will fail. It also cannot interact with scanned, non-editable PDF files.
How can I copy text from a scanned PDF that won't let me highlight words?
You cannot copy text directly from a scanned image. You must first use Optical Character Recognition (OCR) software to analyze the image and convert it into selectable text. Once processed, the text can be copied manually or via scripts.
Can I keep the exact PDF formatting when pasting into Microsoft Word?
Yes, provided your extraction method supports it. In Word VBA, you can use the PasteAndFormat method with the wdFormatOriginalFormatting parameter. However, using a dedicated PDF-to-Word converter often yields far better layout results than simple copy-pasting.




