Reply
 
Thread Tools Display Modes
  #1   Report Post  
ad
 
Posts: n/a
Default Using wdPageBreak without losing the selected Paragraph.

I am currently trying to write a macro to search for a particular style in a
Word document, and every time it is encountered insert a page break.
This seemed failry straightforwards. However, the problem I am having is
that the text contained in the Style is being replaced by the page break, so
I am getting page breaks without retaining the original paragraphs.

I obviously want to have both the page breaks and the paragraphs I have
searched for present.

Below is my code. Any suggestions much appreciated. I basically need a way
of making the Range the cursor input to the paragraph rather than the whole
paragraph itself and I am stuck as to how to do this.


Public Function InsertPageBreak()

Dim para As Word.Paragraph

For Each para In e3Doc.Paragraphs
If para.Style = "ScheduleTitle" Then
para.Range.InsertBreak Type:=wdPageBreak
End If
Next para
End Function

Any help very much appreciated. Adam
  #2   Report Post  
Daiya Mitchell
 
Posts: n/a
Default

Instead of a macro, cannot you define the style to have a Page Break Before?


On 5/6/05 8:15 AM, "ad" wrote:

I am currently trying to write a macro to search for a particular style in a
Word document, and every time it is encountered insert a page break.
This seemed failry straightforwards. However, the problem I am having is
that the text contained in the Style is being replaced by the page break, so
I am getting page breaks without retaining the original paragraphs.

I obviously want to have both the page breaks and the paragraphs I have
searched for present.

Below is my code. Any suggestions much appreciated. I basically need a way
of making the Range the cursor input to the paragraph rather than the whole
paragraph itself and I am stuck as to how to do this.


Public Function InsertPageBreak()

Dim para As Word.Paragraph

For Each para In e3Doc.Paragraphs
If para.Style = "ScheduleTitle" Then
para.Range.InsertBreak Type:=wdPageBreak
End If
Next para
End Function

Any help very much appreciated. Adam


--
Daiya Mitchell, MVP Mac/Word
Word FAQ: http://www.word.mvps.org/
MacWord Tips: http://www.word.mvps.org/MacWordNew/
What's an MVP? A volunteer! Read the FAQ: http://mvp.support.microsoft.com/

  #3   Report Post  
ad
 
Posts: n/a
Default

No unfortunately, we need to do it be a macro. Part of the service the
company I work for is Document Automation, and unfortuantely this client
wants a physical break by a macro rather than page break as part of the
formatting.

This is because if you hit return at the start of a style witha page break
you get another page break, which they do not want. They want the breaks to
be disassociated with the styles, hence we have to use a macro.

Any help much appreciated. Adam

"Daiya Mitchell" wrote:

Instead of a macro, cannot you define the style to have a Page Break Before?


On 5/6/05 8:15 AM, "ad" wrote:

I am currently trying to write a macro to search for a particular style in a
Word document, and every time it is encountered insert a page break.
This seemed failry straightforwards. However, the problem I am having is
that the text contained in the Style is being replaced by the page break, so
I am getting page breaks without retaining the original paragraphs.

I obviously want to have both the page breaks and the paragraphs I have
searched for present.

Below is my code. Any suggestions much appreciated. I basically need a way
of making the Range the cursor input to the paragraph rather than the whole
paragraph itself and I am stuck as to how to do this.


Public Function InsertPageBreak()

Dim para As Word.Paragraph

For Each para In e3Doc.Paragraphs
If para.Style = "ScheduleTitle" Then
para.Range.InsertBreak Type:=wdPageBreak
End If
Next para
End Function

Any help very much appreciated. Adam


--
Daiya Mitchell, MVP Mac/Word
Word FAQ: http://www.word.mvps.org/
MacWord Tips: http://www.word.mvps.org/MacWordNew/
What's an MVP? A volunteer! Read the FAQ: http://mvp.support.microsoft.com/


  #4   Report Post  
Daiya Mitchell
 
Posts: n/a
Default

In that case, you would probably get a quicker answer if you post in a group
with word.vba or word programming in the name. Much higher proportion of
people knowledgeable about macros in those groups, though there are some
here.


On 5/6/05 8:53 AM, "ad" wrote:

No unfortunately, we need to do it be a macro. Part of the service the
company I work for is Document Automation, and unfortuantely this client
wants a physical break by a macro rather than page break as part of the
formatting.


  #5   Report Post  
Greg
 
Posts: n/a
Default

ad,

How about something like:

Sub InsertPageBreak()
Dim oPara As Word.Paragraph
Dim myRange As Range
For Each oPara In ActiveDocument.Paragraphs
If oPara.Style = "Heading 1" Then
Set myRange = oPara.Range.Duplicate
myRange.Collapse Direction:=wdCollapseEnd
myRange.MoveEnd Unit:=wdCharacter, Count:=-1
myRange.InsertBreak Type:=wdPageBreak
End If
Next oPara
End Sub

Does your company pay good?

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing selected text Tristazee Microsoft Word Help 12 April 28th 10 09:36 AM
Cannot print selected pages from a large word document AMB Microsoft Word Help 1 April 29th 05 08:56 PM
Why did "delete" key discontinue to delete a selected word, line . Walter Microsoft Word Help 1 March 2nd 05 08:56 PM
Cannot print selected pages from a large word document Allen B Microsoft Word Help 0 February 23rd 05 03:09 PM
Losing section header formatting during TOC updates!! Alan Miller Microsoft Word Help 1 February 17th 05 12:14 AM


All times are GMT +1. The time now is 09:18 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"