logo
search
VBA & Macro Problems

How to Identify and Skip Embedded PDF Files in Word VBA

WPS EditorWPS Editor Oct 12, 2026 868 views

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.

How to Identify and Skip Embedded PDF Files in Word VBA
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.
Before you start

Ensure you have enabled the Developer tab in your Word application and backed up your document before running new VBA macros.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to launch the Visual Basic for Applications (VBA) editor.

2
Iterate through shapes

Write a For Each loop to iterate through the InlineShapes or Shapes collection within your ActiveDocument.

3
Verify OLE object type

Use an If statement to check if the shape is an OLE object, such as 'If objShape.Type = wdInlineShapeEmbeddedOLEObject Then'.

4
Check the ProgID and skip

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.

Use OLEFormat.ProgID or ClassType to Filter Out PDF Objects
Identifying Acrobat ProgIDs: Adobe Acrobat objects typically use the ProgID 'AcroExch.Document' or a variation. Always check for partial string matches (e.g., 'AcroExch') to ensure different versions of Adobe software are successfully caught and skipped.
Advanced Macro Support

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. 1. Download and Install WPS Office: Get the latest version of WPS Office from the official website and install it on your computer.
  2. 2. Open Your Document in WPS Writer: Launch WPS Writer and open your macro-enabled Word document (.docm or .doc).
  3. 3. Access Developer Tools: Navigate to the Developer tab on the top ribbon to easily access the VBA editor.
  4. 4. Run Your OLE Script: Paste or modify your VBA code to process embedded objects and run the macro securely.
Highly compatible with Microsoft Office VBA scripts and macro functions.Seamlessly handle DOC, DOCX, and DOCM file formats.Lightweight installation with fast document processing speeds.User-friendly Developer tab for easy script editing and debugging.
microsoft office alternative - wps office

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.