Replace section break and insert new header (NOT same as previous)

D

Debra Farnham

Hi All (again)

Win2K Word2K

I am attempting to write some code that will:

1. Find the previous page break and replace it with a next page break
2. Create a header in the last section of the document that includes the
word Page, the page number and some other text. (the other text will be
broken up over a couple of lines)

This is where I'm at so far:
****************************************************************************
********
'Removes previous page break, inserts next page section break and sets
header NOT to same as previous

Dim intSection as integer


Application.Browser.Previous
Selection.TypeBackspace
Selection.InsertBreak Type:=wdSectionBreakNextPage


intSection = ActiveDocument.Range(0,
Selection.Sections(1).Range.End).Sections.Count

ActiveDocument.Sections(intSection).Headers(wdHeaderFooterPrimary).LinkToPre
vious = False

ActiveDocument.Sections(intSection).Headers(wdHeaderFooterPrimary).Range.Tex
t = vbTab & "Page "
****************************************************************************
**************

I'ts not very pretty (at least the replacing of the page break) and I'm
wondering if there is a "smoother" way of doing that AND I'm stumped as to
how to get the page number in after the word "page" along with some other
text.

TIA for any assistance you can provide.

Debra
 
D

Debra Farnham

Got that all to work using:

Dim intSection As Integer
Dim intPreviousPosition As Integer

intPreviousPosition = Selection.Range.End
Selection.GoTo What:=wdGoToPage, Which:=wdGoToPrevious
Selection.TypeBackspace
Selection.InsertBreak Type:=wdSectionBreakNextPage

intSection = ActiveDocument.Range(0,
Selection.Sections(1).Range.End).Sections.Count

ActiveDocument.Sections(intSection).Headers(wdHeaderFooterPrimary).LinkToPre
vious = False

Dim myrange As Range
Set myrange =
ActiveDocument.Sections(intSection).Headers(wdHeaderFooterPrimary).Range
myrange.InsertBefore vbTab & "Page "
myrange.Start = myrange.Start + 6
ActiveDocument.Fields.Add Range:=myrange, Type:=wdFieldEmpty,
Text:="PAGE"
myrange.InsertAfter ". " & vbCr
myrange.Start = myrange.End

With myrange
.MoveEnd unit:=wdParagraph, Count:=1
.InsertAfter vbTab & strBN & " in-Ch."
End With
**********************************************

Now I just need to make sure (before creating the header page numbering and
inserting the text) that I'm not in the First Page Header for the section.
An extra line of text gets inserted into the First Page Header.

Any help would be greatly appreciated

Debra
 
D

Doug Robbins - Word MVP

I think that this is the same question as the one that you asked in your
later post to which I have posted a response.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
W

Word Heretic

G'day "Debra Farnham" <[email protected]>,

The last bit is done more easily like this:

Change
ActiveDocument.Sections(intSection).Headers(wdHeaderFooterPrimary).Range.Tex
t = vbTab & "Page "

to

Dim Insert as Range

.....

Set Insert = _
ActiveDocument.Sections(intSection).Headers(wdHeaderFooterPrimary).Range

Insert.InsertAfter vbtab & "Page "
Insert.Collapse wdcollapsend
Insert.Fields.Add Insert, wdFieldPage

....

Set Insert = Nothing


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Debra Farnham reckoned:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top