We help IT Professionals succeed at work.
Get Started

Get word text after search string

Last Modified: 2013-12-26
I'm stumped; I've played around and adapted the following from some code that I found here (thanks yall) and I can ALMOST get what I need, but not quite.

If you see the following text, I am trying to retrieve the paragraph that is after I have searched and found the common text "Purpose/scope:".  The code below selects all of it.  I'd like to copy the text either into field in another word doc, or into an access field, but for right now all I'm really concerned about is how to select and copy only paragraph following purpose/scope, not the entire section.

PURPOSE/SCOPE:      This procedure will provide the guidelines to assist the Technician in the shutdown of the Towers.

Here's my code:  (once again, "borrowed" from this site)

Sub searchtext()
    Dim rng As Range
    Dim para As Paragraph
    Dim sSearch$
   sSearch = "Purpose/Scope:"
    Set rng = ActiveDocument.Range
    With rng.Find
        .Execute Findtext:=sSearch
        Selection.MoveRight Unit:=wdWord, Count:=1
    End With
    Set para = rng.Paragraphs(1)
    Set rng = para.Range
    For Each para In rng.Paragraphs
      If Selection.Find.Execute(sSearch, Wrap:=wdWrapAlways) = True Then
        rng.Start = Selection.Range.Start
       rng.Expand Unit:=wdParagraph
      MsgBox "Searchtext " & sSearch & " not found."
   End If
    Next para
End Sub

Thanks in advance!

Watch Question
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE