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

Tip: Looking for answers? Try searching our database.

Finding and Pasting All Pages Word Appears On Into a New Doc

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
syrney170 - 29 Jan 2008 21:34 GMT
Hello,

I have run into a problem where i am trying to take a file that has
dozens of pages and needs to be split into multiple documents and I
would like to do this with a macro.  This is soemthing that I do each
month so it would be nice to automate it to some extent.  Each page
contains a person's name towards the top of the page.  i would like
find all of the pages that have "Tom" on it and paste the entire
content of those pages into another document that is saved with the
name "Tom". So in the end I will have a file for each distinct name
with just the pages of info related to that person.  I was able to get
it to paste the first instance but when using the loop argument could
not figure out how to get it to not just keep pasting the first
instance of "Tom" that it finds. Here is the code I had related to his
so far.

Any help would would be greatly appreciated.  I am still very new to
macros in Word so there probably is a better method to doing what i am
trying to accomplish.  If so please let me know.  I did look through
this group alreayd and did not quite find anything that answered this
question closely enough for me just to take something and change it.

Dim myRange As Range

Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
Windows(2).Activate
With Selection.Find
Do While .Execute(FindText:="Tom", MatchWildcards:=False,
Wrap:=wdFindContinue, Forward:=True) = True
       Windows(2).Activate
       ActiveDocument.Bookmarks("\page").Range.Select
       Set myRange = ActiveDocument.Bookmarks("\page").Range
       myRange.Copy
       Windows(1).Activate
       ActiveDocument.PageSetup.Orientation = wdOrientLandscape
       Selection.PasteAndFormat (wdPasteDefault)

   Loop
End With

End Sub

Thanks,

James Jordan
Doug Robbins - Word MVP - 30 Jan 2008 03:18 GMT
If you Cut the \Page Range from the source document, it will not be there to
be found again.

Signature

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

> Hello,
>
[quoted text clipped - 41 lines]
>
> James Jordan
 
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.