macro help

B

beer_on

Doug helped me fantastically with a macro in Word, thank you, now when
I try to run it, a new document opens and I get a runtime error 5941,
which pretty much means there is nothing in the document. I would like
the macro to run in the open document and not open a new document. Any
help would be appreciated.
 
B

beer_on

I don't think that is the problem, I think the problem is in the
Selection.Find.Style line. I don't know anything about this stuff so
if I need to change something to coincide with my document please let
me know..

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("Heading1,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
 
G

Guest

Hi (e-mail address removed),

You are right. The line following 'Selection.Find.Style =' should not begin
on a new line, but follow the preceding = immediately.

Success,
Cooz
 
B

beer_on

Sorry, didn't notice that but it got cropped when I pasted it here. In
the macro it is all one line. I did the same with the "Do while" line
and the "Wrap" line so they are one line too.
 
B

beer_on

Does it matter that in the document there is no header just a line that
starts "(New Section)", which acts as a header? This is where I want
each new page to start.

This was my original post:
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.
 

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