Solved

VBA to remove a specific paragraph from word document

Posted on 2016-11-02
4
22 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
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 48

Expert Comment

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

Author Closing Comment

by:excelismagic
Comment Utility
thanks.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now