Re: One more question



Thank you for that. Curiously, this one does the same thing as a page break-
it moves my word to the far left of the screen, losing the spaces in front of
it. (I'm converting a text file report to a Word document, and want to keep
the alignment of my word with other specific columns of textual information.)

Strangely, using the Style as explained by Shauna is actually the only
option I've seen that gets me the desired result. I just can't figure out
why I can't enter the setting from Format-->Paragraph-->Page Break Before
into a macro. "wdPageBreak" is a page break, so you'd think there would be
an equivalent for paragraph page break.

Anyway, thank you all for your unending and patient help. I'll use the
Style solution for now unless I can figure out a true macro. Thanks again!


"Graham Mayor" wrote:

Sub Scratchmacro()
Dim oRng As Word.Range
Dim oRngDup As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.MatchWildcards = False
.Text = "Smith"
.Replacement.Text = "^pSmith"
.Execute replace:=wdReplaceAll
End With

with put a paragraph break before 'Smith'

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


JAnderson wrote:
That is an excellent tutorial on styles; thank you! For my personal
use, I think I'll start using these.

I tried it and it worked perfectly. Part of my challenge, however, is
creating a file for other users. These users are able to run macros,
but applying styles might be a bit much.

Is there some way I can use the macro Greg gave me to insert a
paragraph break instead of a page break? This is what he gave me:

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

Isn't there a property that would allow me to insert paragraph breaks
instead of page breaks?

Thanks!

"Shauna Kelly" wrote:

Hi JAnderson

Today is the day you learn about styles!

Make a backup of your document before you do all this, in case of
accidents.

Create a paragraph style and name it Smith (or something related to
the magic word whose paragraph you always want to be at the top of a
page).

Modify this new style's paragraph formatting so it has page break
before and, just for the moment, modify its font to give it a funny
colour (bright green, pink, whatever). The funny colour will help
you see what's going on. (See How to modify styles in Microsoft Word
http://www.ShaunaKelly.com/word/styles/ModifyAStyle.html)

Use Find and replace as follows:
- Find What = your magic word
- Replace with = your magic word
- Click More
- Click in the Replace with box, then click Format > Style and click
on your style name.
- Click Replace all.

Bingo. All paragraphs containing your magic word are in your funny
colour and are at the top of a page.

Now, delete all the manual page breaks. To do that, use Find and
Replace again:
- Click in Find What. Click Special and choose Manual Page Break.
- Leave Replace With empty.
- Click Replace all.

All OK? Then modify your style again to put the colour back to
Automatic.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


"JAnderson" <JAnderson@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:BE78DA73-8A63-4469-8007-AE6F5AEE6687@xxxxxxxxxxxxxxxx
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: One more question
    ... Dim oRng As Word.Range ... Dim oRngDup As Word.Range ... Set oRng = ActiveDocument.Range ... with put a paragraph break before 'Smith' ...
    (microsoft.public.word.vba.general)
  • Re: Can I check the spelling in only one of multiple form fields?
    ... Here is a modified version of your macro. ... Sub CheckMeExit() ... Dim oRng As Word.Range ... Set oRng = ActiveDocument.FormFields.Range ...
    (microsoft.public.word.docmanagement)

Loading