Deleting a page based on text search

D

Damo

Word 2003 Macro question:
I have 14 x 320 page word documents (School subject reports) created via
mail merges. At irregular intervals in each document there will be a page
which I wish to delete (the student does not do this subject). There is text
present from the mail merge template, however the is no data inserted into
this page. For example, on the pages I wish to delete the teacher name is
blank.
I have created a macro and attached it to a toolbar so that I can delete the
active page manually as I scroll through the document. However I would rather
have the macro search through the document, and where it finds the string
"Subject Teacher : " with no name next to it, then it can call the delete
page macro I made. However I cannot figure out how to make it search for that
string PLUS the missing teacher name (many different teacher names).
Can anybody help with this?
 
J

Jean-Guy Marcil

Damo was telling us:
Damo nous racontait que :
Word 2003 Macro question:
I have 14 x 320 page word documents (School subject reports) created
via mail merges. At irregular intervals in each document there will
be a page which I wish to delete (the student does not do this
subject). There is text present from the mail merge template,
however the is no data inserted into this page. For example, on the
pages I wish to delete the teacher name is blank.
I have created a macro and attached it to a toolbar so that I can
delete the active page manually as I scroll through the document.
However I would rather have the macro search through the document,
and where it finds the string "Subject Teacher : " with no name next
to it, then it can call the delete page macro I made. However I
cannot figure out how to make it search for that string PLUS the
missing teacher name (many different teacher names).
Can anybody help with this?

Try something like the following. You will need to find a way to determine
the exact string you need to search for when there are no teacher names
(strSearch).

'_______________________________________
Dim strSearch As String
Dim rgeStart As Range

Set rgeStart = Selection.Range

strSearch = "Subject Teacher :" & Chr(13)

With ActiveDocument.Range.Find
.Text = strSearch
Do While .Execute
With .Parent
.Select
With Selection
.Bookmarks("\Page").Range.Delete
.Characters(1).Delete
End With
End With
Loop
End With

rgeStart.Select

Application.Browser.Target = wdBrowsePage
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

Damo

Jean-Guy

Absolutely Brilliant. Your coding worked instantly with no modifications
necessary.

Thankyou very much.

Damo
 

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