How to Delete All Floating Shapes from a Word Document with VBA
Question details
The user needs a reliable method to delete all floating shapes from a Word document because standard methods cannot detect them.

- 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.
Always create a backup copy of your document before running macros, as VBA actions cannot always be easily undone using the standard Undo feature.
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.
Open the target Word document. Press 'Alt + F11' on your keyboard to open the Microsoft Visual Basic for Applications (VBA) editor.
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.
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
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.

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. Download WPS Office: Install WPS Office and ensure you are using the version that includes VBA support.
- 2. Open the Developer Tools: Open your document in WPS Writer. Go to the 'Developer' tab on the ribbon.
- 3. Access the VBA Editor: Click on 'Macros' or the 'Visual Basic' icon to open the code editor.
- 4. Execute Your Script: Insert a new module, paste your shape-deleting VBA code, and click 'Run' to instantly clean up your document.

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.




