VBA & Macro Problems

How to Delete All Floating Shapes from a Word Document with VBA

Aamir Naveed AkramAamir Naveed Akram Nov 4, 2026 872 views

Question details

The user needs a reliable method to delete all floating shapes from a Word document because standard methods cannot detect them.

How to Delete All Floating Shapes from a Word Document Using VBA
Product
Word
Device & OS
not provided
Scenario
Removing unwanted floating objects, such as watermarks resulting from a PDF-to-Word conversion, from a document.
Observed behavior
The standard ^g Find and Replace function fails to remove the objects because it only identifies inline pictures, leaving floating Word shapes untouched.
Before you start

Always create a backup copy of your document before running macros, as VBA actions cannot always be easily undone using the standard Undo feature.

Solution 1Recommended

Run a Custom VBA Macro to Delete Floating Shapes

Use a VBA macro to count and iterate backwards through all floating shapes in the active document, deleting them one by one.

Because floating shapes exist on a different drawing layer than regular text and inline graphics, the built-in Find and Replace tool (^g) ignores them. A VBA macro specifically targeting the 'Shapes' collection is required.

It is crucial to iterate backwards (from the total count down to 1) when deleting objects from a collection in VBA to prevent shifting index numbers from causing runtime errors.

1
Open the VBA Editor

Open the target Word document. Press 'Alt + F11' on your keyboard to open the Microsoft Visual Basic for Applications (VBA) editor.

2
Insert a New Module

In the VBA editor, click on 'Insert' in the top menu bar, and then select 'Module'. This will open a blank text window where you can write your script.

3
Paste the Macro Code

Copy and paste the following code into the module window: Sub DeleteAllShapesFromDoc() Dim i As Long Dim shapeCount As Long shapeCount = ActiveDocument.Shapes.Count For i = shapeCount To 1 Step -1 ActiveDocument.Shapes(i).Delete Next i End Sub

4
Run the Macro

Press 'F5' on your keyboard or click the green 'Run' triangle button in the top toolbar to execute the macro. All floating shapes in the main body of the document will be deleted.

Run a Custom VBA Macro to Delete Floating Shapes
Remaining Objects: If some objects still remain in your document after running the macro, they may be inline shapes, shapes located in headers/footers, or other specific object types that require separate VBA handling.
Efficient Word Processing with WPS Office

Manage Documents and Run Macros Easily with WPS Writer

WPS Office offers robust VBA support in its Writer application, allowing you to seamlessly run macros to delete floating shapes, watermarks, and automate repetitive document tasks.

  1. 1. Download WPS Office: Install WPS Office and ensure you are using the version that includes VBA support.
  2. 2. Open the Developer Tools: Open your document in WPS Writer. Go to the 'Developer' tab on the ribbon.
  3. 3. Access the VBA Editor: Click on 'Macros' or the 'Visual Basic' icon to open the code editor.
  4. 4. Execute Your Script: Insert a new module, paste your shape-deleting VBA code, and click 'Run' to instantly clean up your document.
Fully compatible with Microsoft Word document formats (.docx, .doc)Supports advanced VBA and Macro scripting for document automationFree, lightweight, and features a user-friendly tabbed interface
microsoft office alternative - wps office

Frequently Asked Questions

Why does Find and Replace (^g) miss floating shapes?

The Find and Replace tool utilizing the ^g code specifically targets 'inline graphics' that are embedded directly within the text flow. Floating shapes are anchored to the text but reside on a separate drawing layer, making them invisible to standard text-based search functions.

How can I remove inline shapes using VBA?

To remove inline shapes, you must target a different object collection in VBA. You can modify the provided macro by replacing 'ActiveDocument.Shapes' with 'ActiveDocument.InlineShapes' to locate and delete graphics embedded within the text line.

Why didn't the macro delete shapes in my headers and footers?

The 'ActiveDocument.Shapes' collection only targets objects within the main body text (the main story range). To delete shapes in headers or footers, you need a macro that loops through each 'StoryRange' in the document to locate and delete the floating objects stored in those specific sections.