Highlight all lines containing phrase

L

Luke

Hi All,
In word 2007 I have a very large file open which is lines of a backup script.

I am trying to isolate all of the lines which start with the phrase
'source=' and highlight them. In this way I can copy them and paste them into
a new document, which will just show me all of the source folders, making it
easier for me to go through what we are backing up.

I know I can find all and highlight the 'source=' phrase with reading
highlight, but I cant copy all of those.. and it also wont highlight the
whole line.. it only highlights the phrase 'source='.

Does anyone know if its possible to do what I am trying to do and if so.. how?

Cheers,
Luke
 
D

Doug Robbins - Word MVP

Use a macro containing the following code:

Dim source As Document, target As Document
Set source = ActiveDocument
Set target = Documents.Add
source.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="source=", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
target.Range.InsertAfter Selection.Bookmarks("\line").Range.Text &
vbCr
Selection.Collapse wdCollapseEnd
Selection.MoveRight wdCharacter, 1
Loop
End With
target.Activate

While it does not do exactly what you asked for, I believe that it gives you
what you want.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
L

Luke

Thanks for your response! However I dont know anything about Macros.. I tried
pasting this into the macros window in word 2007 but I get a 'compile error:
invalid outside procedure'

I had a look at help but I think I actually got dumber trying to figure out
what is going on :(

Could you let me know where this code goes to make it work?

Thanks again for your help :)
 
J

Jay Freedman

It's like Doug gave you the filling for a sandwich and left you to supply the
bread. It needs a "Sub" line at the beginning and an "End Sub" line at the end.
Follow the instructions at http://www.gmayor.com/installing_macro.htm to get
this working.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
L

Luke

Thank you both very much for your help!!! A bit of fiddling around with the
macro thingy and it works now..

Excellent :)
 

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