Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VBA to remove a specific paragraph from word document

Posted on 2016-11-02
4
33 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 50

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 50

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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