How to extend selection,copy,paste in new doc, repeat

M

Markus J

This is a two part question from a full time vba newbie

The project:

We receive over 50 teacher reviews in one word document. We need to
search through this 100 page document and copy each teachers evaluation into
a new document. The only distinguishing feature between each teacher's
evaluation is the teachers name in 18pt font, which font size occurs no where
else in the document except by the teachers name.

My purposed solutions:

I was thinking of using this instance to extend the selector and
make the appropriate copies.

My problems:

1)I can't figure out how to extend the selector to a font.size
instance or use the range method to select the name by font size and add a
distinguishing character "*" before the teachers name so it can be selected
with selector.extend.
2) When I run the part of my code that copies each
selection.extend character:="*" and pastes it into a new word document,
closes and saves it, I can't seem to get the selector to unselect the last
selection and re-extend itself. I've toyed with deleting the last selection
to force it to copy the next and just not save the document when the process
is done but it only works for the first time through the loop.

My Code:

Sub CopyPasteSelection()


Dim msgStat As Long
msgStat = vbYes


Do While msgStat = vbYes

Selection.Extend Character:="*"
Selection.Copy
Documents.Add
ActiveWindow.ActivePane.LargeScroll Down:=1
Selection.PasteAndFormat (wdPasteDefault)

ActiveDocument.Save

ActiveWindow.Close
Selection.Delete

msgStat = MsgBox("Continue to the next step?", vbYesNo)

Loop

Documents.Close SaveChanges:=wdDoNotSaveChanges


End Sub




Notes:

I am VERY new at VBA and programming in general and would really
appreciate the help on this project. I'm sure it's something simple but
simple problems are still a mountain at this point.
 
J

Jim Aksel

Markus - sounds like an interesting approach. There is some risk to using
the change in Font Size as your sole discriminator, although it makes sense.

This newsgroup is dedicated to Microsoft Project, a scheduling and planning
desktop application. You need to repost to the Microsoft Word Programming
news group for a better answer. Try here (English - US).

http://www.microsoft.com/office/com...crosoft.public.word.vba.general&lang=en&cr=US
--
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com
 

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