Solved

VBA to remove a specific paragraph from word document

Posted on 2016-11-02
4
38 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
[X]
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
  • 2
  • 2
4 Comments
 
LVL 51

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 51

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.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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