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

S

syrney170

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
 
D

Doug Robbins - Word MVP

If you Cut the \Page Range from the source document, it will not be there to
be found again.

--
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
 

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