VBA : Remove All Pictures Include Caption Text, Table Formatting

Susanto3311
3StarLounger
Posts: 243
Joined: 17 Feb 2022, 05:16

VBA : Remove All Pictures Include Caption Text, Table Formatting

Post by Susanto3311 »

hi all
how to fix this macro code to remove all pictures from document
this code work but not perfect

Code: Select all

Sub DitchPictures()
Dim objPic As InlineShape
For Each objPic In ActiveDocument.InlineShapes
objPic.Delete
Next objPic
End Sub
after run macro, only picture/images gone/deleted but text & table format not gone
i want the code can gone everything (images, caption text & table/border format)

here picture screen shoot (before ,after run macro, my expected result) to make more clear
thank for anyone help me

susant
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78633
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA : Remove All Pictures Include Caption Text, Table Formatting

Post by HansV »

Please attach a sample document.
Best wishes,
Hans

Susanto3311
3StarLounger
Posts: 243
Joined: 17 Feb 2022, 05:16

Re: VBA : Remove All Pictures Include Caption Text, Table Formatting

Post by Susanto3311 »

hi hans, this my sample file
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78633
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA : Remove All Pictures Include Caption Text, Table Formatting

Post by HansV »

Wouldn't the easiest solution be to delete the entire table?

Code: Select all

Sub DeletePhotos()
    ActiveDocument.Tables(1).Delete
End Sub
Best wishes,
Hans

Susanto3311
3StarLounger
Posts: 243
Joined: 17 Feb 2022, 05:16

Re: VBA : Remove All Pictures Include Caption Text, Table Formatting

Post by Susanto3311 »

hi hans, you're right..
thanks for your solution