One more question

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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?



.



Relevant Pages

  • Re: Macro Help Needed
    ... Dim oRng As Word.Range ... Set oRng = Selection.Range ... Again it was late when I made the modification to the quote macro. ... pressing enter twice to place a blank paragraph between your current ...
    (microsoft.public.word.newusers)
  • Re: Macro Help Needed
    ... Dim oRng As Word.Range ... Set oRng = Selection.Range ... Again it was late when I made the modification to the quote macro. ... current text paragraph and a new text paragraph and then you want ...
    (microsoft.public.word.newusers)
  • Re: Macro Help Needed
    ... Dim oRng As Word.Range ... Set oRng = Selection.Range ... Again it was late when I made the modification to the quote macro. ... current text paragraph and a new text paragraph and then you want ...
    (microsoft.public.word.newusers)
  • Re: Macro Help Needed
    ... Dim oRng As Word.Range ... Set oRng = Selection.Range ... Again it was late when I made the modification to the quote macro. ... comes the closest to the key word count in my manuscript a prize, ...
    (microsoft.public.word.newusers)
  • Re: Can I check the spelling in only one of multiple form fields?
    ... I used portions of another macro that I ... Sub CheckMeExit() ... Dim oRng As Word.Range ... Set oRng = ActiveDocument.FormFields.Range ...
    (microsoft.public.word.docmanagement)