Solved

VBA to remove a specific paragraph from word document

Posted on 2016-11-02
4
30 Views
Last Modified: 2016-11-03
I have a document with too many paragraphs repeated as shown in the attached workbook.

in the attached word i have the paragraph that i need to get red of regardless in which page it is.

can this be automated with VBA?
EE.docx
0
Comment
Question by:excelismagic
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41871627
Hi,

pls try

Sub LongStringFindReplace()
Dim oSourceDoc As Document
Dim srchTxt As String
Dim replaceRng As Range
Dim i As Long
  srchTxt = Selection.Range.Text
  ActiveDocument.Range(0, 0).Select
  If Len(srchTxt) > 250 Then
    With Selection.Find
      .Text = Left(srchTxt, 250)
      .Forward = True
      .Wrap = wdFindContinue
      Do While .Execute
        Do While srchTxt Like Selection.Text & "*"
            If Selection.Text = srchTxt Then
                Selection.Delete
                Exit Do 'loop
            End If
            Selection.MoveEnd Unit:=wdCharacter, Count:=1
        Loop
      Loop
    End With
  Else
    With Selection.Find
      .Text = srchTxt
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindContinue
      .Execute Replace:=wdReplaceAll
    End With
  End If
End Sub

Open in new window

Regards
0
 
LVL 3

Author Comment

by:excelismagic
ID: 41871870
thanks very much Rgonzo1971 but it did not solve the problem

here is part of the full document attached.

i am trying to remove the part shown in screenshot below from this file and the macro i ran, did not fix it.
 
EE.pngEE.docx
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 41871877
pls select the part you want to delete before running the code
0
 
LVL 3

Author Closing Comment

by:excelismagic
ID: 41872428
thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question