Results 1 to 3 of 3

Thread: Delete all paragraphs containing a particular image using a VBA macro in MS Word

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Delete all paragraphs containing a particular image using a VBA macro in MS Word

    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 !

  2. #2
    Junior Member
    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0
    i have made this for text comparision you can compare with height,width and more. for comparing with your local machine image

    try this

    Code:
    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


    Code:
    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
    Last edited by ashu1990; 09-11-2013 at 06:40 PM.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0
    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

    Free large file exchange service without size limits

Similar Threads

  1. Replies: 7
    Last Post: 08-24-2015, 10:58 PM
  2. Macro to delete trailing X's
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 03-29-2013, 12:43 PM
  3. Replies: 1
    Last Post: 10-16-2012, 01:53 PM
  4. Replies: 4
    Last Post: 08-14-2012, 03:17 AM
  5. Adding Scroll bar to image box in vba
    By princ_wns in forum Excel Help
    Replies: 1
    Last Post: 12-13-2011, 09:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •