One more question
- From: JAnderson <JAnderson@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 15 Dec 2006 16:08:00 -0800
So this does exactly what I asked, but sometimes my text in the original
document appears in the middle of the page, with several spaces before it. I
want to retain this position, and the only way I can do that is if I insert a
page break in the line BEFORE my text.
I can't insert the blank text into the macro itself because the number of
spaces is variable. Basically, I want to know if it's possible to have the
macro find my text, then insert a break at the beginning of the line or on
the previous line (which is always blank in my document).
Thanks!!
"JAnderson" wrote:
Um, wow- that was perfect. My document has about 300 instances of this.
particular word, so I like this macro. Could a style do the same thing with
such a large document?
I'm a bit of a novice with VB, but I have to admit I have NO idea why/how
this works, but it's perfect.
Thank you!
"Greg Maxey" wrote:
A more conventional approach might be to define a style with page break
before and apply that style to the text where appropriate.
However, to answer your question this might work:
Sub Scratchmacro()
Dim oRng As Word.Range
Dim oRngDup As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "Smith"
While .Execute
Set oRngDup = oRng.Duplicate
oRngDup.Collapse wdCollapseStart
oRngDup.InsertBreak Type:=wdPageBreak
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
JAnderson wrote:
Greetings,
I'm trying to insert multiple page breaks in a very large document.
Essentially, every time a certain word appears (ex: "Smith"), I want
Word to insert a page break.
This should be easy because my document has a lot of areas which
should be at the top of a page (my company's name), and every single
time that name appears, I want a page break in front of it.
Is there a way to write a macro to insert a page break before a
particular word or phrase?
- Follow-Ups:
- Re: One more question
- From: Shauna Kelly
- Re: One more question
- References:
- Re: Simple macro question - multiple page breaks
- From: Greg Maxey
- Re: Simple macro question - multiple page breaks
- Prev by Date: Re: Why does Design Mode turn on when opening a protected file?
- Next by Date: Chart drives me nuts !!! HELP
- Previous by thread: Re: Simple macro question - multiple page breaks
- Next by thread: Re: One more question
- Index(es):
Relevant Pages
|