Microsoft Word – Use a VBA Macro to Delete All Images

You can use a VBA macro to find and delete all pictures in a Microsoft Word document.

Before starting, make sure macros are allowed in your document.
If they are not, save the file as a “.docm” Word document to allow macros to run.

1.) Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

2.) Click on Insert and select Module to insert a new module.

3.) Copy and paste the following VBA code into the module:

Sub DeleteAllPictures()
Dim shp As Shape
Dim inShp As InlineShape

' Delete Shape objects
For Each shp In ActiveDocument.Shapes
If shp.Type = msoPicture Then shp.Delete
Next shp

' Delete InlineShape objects
For Each inShp In ActiveDocument.InlineShapes
If inShp.Type = wdInlineShapePicture Or inShp.Type = wdInlineShapeLinkedPicture Then
inShp.Delete
End If
Next inShp
End Sub

4.) Either click on the green “Run” button..
Or go to the menu, select Run, and then click on “Run Sub/UserForm” from the drop-down menu.

Leave a Reply