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 / June 2007

Tip: Looking for answers? Try searching our database.

Deleting a page based on text search

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Damo - 18 Jun 2007 19:53 GMT
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?
Jean-Guy Marcil - 19 Jun 2007 05:41 GMT
Damo was telling us:
Damo nous racontait que :

> Word 2003 Macro question:
> I have 14 x 320 page word documents (School subject reports) created
[quoted text clipped - 11 lines]
> 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
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Damo - 19 Jun 2007 09:00 GMT
Jean-Guy

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

Thankyou very much.

Damo

> Damo was telling us:
> Damo nous racontait que :
[quoted text clipped - 44 lines]
> Application.Browser.Target = wdBrowsePage
> '_______________________________________
 
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.