word macro

  • Thread starter Thread starter beer_on
  • Start date Start date
B

beer_on

I have a document that could be up to 100 pages long with many
different headings. I am trying to write a macro that would only print
the heading and the text following to fill up only one page. Then page
2 would start with the second heading and the text that follows to fill
that page, and so on for as many headings there are. So if I had 5
headings, the document would only print five pages. One problem also is
that the headings all start with (, ex.: (heading1)
This printout is for reference and that is why I am trying to reduce
the pages. Any help would be greatly appreciated, I am new to VBA and
have been struggling.
 
Something like:

Dim Source As Document, Target As Document, arange As Range
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading
1,Section,Main,h1,Heading1")
With Selection.Find
Do While .Execute(FindText:="", MatchWildcards:=False, Wrap:=wdFindStop,
Forward:=True) = True
Set arange = Selection.Bookmarks("\page").Range
Target.Range.InsertAfter arange.FormattedText
Loop
End With


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

Back
Top