How to Identify and Skip Embedded PDF Files in Word VBA
Question details
The user needs to programmatically detect and bypass embedded PDF files when interacting with OLE objects in a Word document using a VBA macro.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating the processing of embedded OLE objects within a Word document without triggering unwanted PDF applications to open.
- Observed behavior
- When a VBA script attempts to open or copy embedded objects using DoVerb, the script freezes or gets stuck if it encounters an unsupported embedded PDF or Acrobat object.
Ensure you have enabled the Developer tab in your Word application and backed up your document before running new VBA macros.
Use OLEFormat.ProgID or ClassType to Filter Out PDF Objects
Inspect the OLE properties of each embedded object to verify its class identifier before calling the DoVerb method.
By checking the Programmatic Identifier (ProgID) or ClassType, your VBA macro can determine if a specific embedded shape is a PDF file. If the identifier string contains 'PDF' or 'AcroExch', the script can bypass the execution command, preventing the macro from halting.
Press Alt + F11 on your keyboard to launch the Visual Basic for Applications (VBA) editor.
Write a For Each loop to iterate through the InlineShapes or Shapes collection within your ActiveDocument.
Use an If statement to check if the shape is an OLE object, such as 'If objShape.Type = wdInlineShapeEmbeddedOLEObject Then'.
Read the objShape.OLEFormat.ProgID or objShape.OLEFormat.ClassType. Use the InStr function to check if it contains 'Acro' or 'PDF'. If it does, use a GoTo statement to jump to the next iteration instead of executing the DoVerb method.

Write and Run VBA Macros Smoothly with WPS Office
WPS Office provides robust VBA support, allowing you to automate repetitive tasks, process embedded OLE objects, and run customized macros with high compatibility and performance.
- 1. Download and Install WPS Office: Get the latest version of WPS Office from the official website and install it on your computer.
- 2. Open Your Document in WPS Writer: Launch WPS Writer and open your macro-enabled Word document (.docm or .doc).
- 3. Access Developer Tools: Navigate to the Developer tab on the top ribbon to easily access the VBA editor.
- 4. Run Your OLE Script: Paste or modify your VBA code to process embedded objects and run the macro securely.

Frequently Asked Questions
What is the ClassType for an embedded Adobe PDF object?
The ClassType or ProgID for an Adobe PDF is typically 'AcroExch.Document' or 'AcroExch.Document.DC', depending on the exact version of the Adobe software installed on the machine.
Why does my VBA script freeze when opening embedded PDFs?
The script freezes because the OLE DoVerb method attempts to launch the associated PDF application. This application might require user interaction, be missing from the system, or block the VBA thread from continuing until manually closed.
Can I extract the PDF file instead of skipping it?
Extracting OLE embedded PDFs via VBA requires more complex workarounds, such as saving the document as a ZIP file (for DOCX formats) and programmatically extracting the contents of the 'embeddings' folder.
Where can I get help for complex VBA and OLE programming issues?
For highly specialized Word VBA and OLE problems, it is recommended to post your code and error logs on dedicated programming forums like Stack Overflow, ensuring you use specific tags for Word and VBA.




