Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Replacing selected text | Microsoft Word Help | |||
Cannot print selected pages from a large word document | Microsoft Word Help | |||
Why did "delete" key discontinue to delete a selected word, line . | Microsoft Word Help | |||
Cannot print selected pages from a large word document | Microsoft Word Help | |||
Losing section header formatting during TOC updates!! | Microsoft Word Help |