Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Select a line based on a string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
takezo.01@gmail.com - 21 Mar 2006 23:52 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.