Select a line based on a string

T

takezo.01

Hello All,

I am looking for a way to search through an entire word document to
find a line beginning with a particular string (multiple words). On
finding this, I need to assign the entire line of text where it is
found to a variable. Really, I only need the text after the string up
until the end of the line, but atleast if I get the entire line I can
work with that. Any help would be greatly appreciated. I have been
researching selections, ranges, find, but I am new to this and am not
getting it to make sense.

Thank You,
Alejandro
 
G

Greg Maxey

Perhaps something like this:

Sub ScratchMacro()
Dim oRng As Word.Range
Dim i&
Dim myStr$
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Text = "Now is the time"
.Execute
If .Found Then
oRng.Select
i = oRng.Characters.Count
oRng.Collapse wdCollapseStart
Selection.Bookmarks("\line").Select
myStr = Selection.Text
myStr = Right(myStr, Len(myStr) - i)
ActiveDocument.Variables("myVar").Value = myStr
End If
End With
 
T

takezo.01

Thank You! Its exactly what I need, and I can understand what its
doing. I was going to leave the office, but I'm so happy I'm just going
to stay and finish this. Again, thanks.

Regards,
Alejandro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top