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
Greg Maxey - 22 Mar 2006 00:16 GMT
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

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
> Hello All,
>
[quoted text clipped - 9 lines]
> Thank You,
> Alejandro
takezo.01@gmail.com - 22 Mar 2006 00:59 GMT
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
> Perhaps something like this:
>
[quoted text clipped - 37 lines]
> > Thank You,
> > Alejandro
Greg Maxey - 22 Mar 2006 02:04 GMT
Ok, but don't blame me if you collapse from overwork and exhaustion ;-)

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
> 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
[quoted text clipped - 44 lines]
>>> Thank You,
>>> Alejandro