View Full Version : Delete all paragraphs containing a particular image using a VBA macro in MS Word
sshishirkumar
09-11-2013, 04:51 PM
I have a word file with some sentences which begin with a particular image/icon/picture (the desktop icon). I use a VBA-macro to perform certain changes in the document. I want to delete all the statements/sentences/paragraph which begin with this particular image in the document? (may be by using the image properties like height=0.34' and width=0.34'etc or by comparing the image with its own locally saved image) please help !
ashu1990
09-11-2013, 06:37 PM
i have made this for text comparision you can compare with height,width and more. for comparing with your local machine image
try this
Sub test()
Dim pic As Shape, a As Shape, b As Shape
''''uses only 2 pics at a time
For Each pic In ActiveSheet.Shapes
If pic.Type = msoPicture Then
If a Is Nothing Then
Set a = pic
ElseIf b Is Nothing Then
Set b = pic
End If
End If
Next pic
''''types of comparision
' a.Height
' a.Width
' a.AutoShapeType
' a.ID
If a.AlternativeText = b.AlternativeText Then
MsgBox "Caught Them"
Exit Sub
End If
End Sub
or use this for all pics comparing height and width
Sub test()
Dim pic As Shape, a As Shape, b As Shape
''''for all the pics
For Each pic In ActiveSheet.Shapes
If pic.Type = msoPicture Then
If pic.Height = 0 And pic.Width = 0 Then
MsgBox "delete your row"
Exit Sub
End If
End If
Next pic
End Sub
sshishirkumar
09-12-2013, 02:13 PM
Hi Thanks for your response,
I have written something similar to your second solution,
Sub DeletePictureParagraphs()
Dim objPic As InlineShape
For Each objPic In ActiveDocument.InlineShapes
If objPic.Height = 0.33 And objPic.Width = 0.33 Then
objPic.Range.Delete
Exit Sub
End If
Next objPic
End Sub
but I am facing a problem. none of the lines which I wanted are getting deleted ( probably the height and width which I mentioned in the code(from the properties of the picture in inches) are not in line with what the code is expecting. I haven't tried the first method which u suggested as I just don't want to depend on comparing the picture from local picture. I have uploaded my file in the below location as I am unable to attach here. Please help. I want to delete all the paragraphs ( statements/sentences) which contain the desktop picture/icon at the beginning of the line.
Free large file exchange service without size limits (http://www.fileconvoy.com/dfl.php?id=g928d3ef108a043ad9993694945c37a7c45dd85 616)
Free large file exchange service without size limits (http://www.fileconvoy.com/dfl.php?id=g928d3ef108a043ad9993694945c37a7c45dd85 616)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.