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 / February 2008

Tip: Looking for answers? Try searching our database.

Extract paragraphs to another document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
New to VBA - 26 Feb 2008 23:58 GMT
I have a long Word document and I need to extract and copy to another
document all the paragraphs containing the word Symbol. I have no problem
with the code to search for Symbol, extend the selection to include the
whole paragraph and copy it to another document, but after the first
occurence of the word Symbol, I don't know how to "go back" to the document
and continue with the search and copy to the new document.

Any suggestions would be appreciated.
Jonathan West - 27 Feb 2008 01:17 GMT
> X-No-Archive: Yes
>
[quoted text clipped - 6 lines]
>
> Any suggestions would be appreciated.

Learn to love the Range object. Almost every element of a Word document has
a Range property. Broadly speaking, an object's Range property is the bit
that would be highlighted if that object were selected.

In addition, a Range object variable acts very much like a Selection, with a
couple of very useful advantages.

1. You can define as many Range objects as you want to. You can even define
an array of Ranges.

2. A range object remains associated with a document even if you activate
another document.

So, for your problem, where you are presently using the Selection to find
your paragraphs, define a range, and use that. It is as simple as defining a
range (call it myRange for instance), set it to the selection or whatever
part of the document you want to search, suing Set myRange = Selection.Range
or similar, and then where you are using With Selection.Find, use instead
With myRange.Find.

Then you could have an additional range variable called myWholePara. Once
you have found something, you can then point myWholePara to the entire
paragraph, with a line of code like this

Set myWholePara = myRange.Paragraphs(1).Range

You can now copy myWholePara elsewhere. myRange hasn't moved, it is still
marking the found word, and so you can do another find to find the next
example.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

New to VBA - 28 Feb 2008 23:17 GMT
>>Learn to love the Range object. <<

Well, I really didn't want to learn to love ranges, but there are a couple
of very interesting messages in the newsgroup mentioning ranges vs.
selections, so I guess I'll have to :-)

Thanks.

Rate this thread:






 
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.