PDA

View Full Version : Solved: Remove page number in footer/last page



ukemike
05-11-2005, 07:59 AM
Guys i have a word document that has "continued on next page" as a footer for each page. How do i turn this off on the last page??


Thanks very much
Mike

fumei
05-11-2005, 08:01 AM
Simple. Make the last page a separate section and remove the footer. If you are asking about how to do this dynamically, that is another story.

ukemike
05-11-2005, 09:28 AM
Gary,

How do i make the last page as new section?
Sorry not to familiar with Word's headers/footers.


Thanks
Mike

MOS MASTER
05-11-2005, 11:51 AM
Hi Mike, :D

Are you building this document page by page?

Or do you want to execute this code on a document that's allready finished?

:whistle:

ukemike
05-11-2005, 11:54 AM
I want to execute this on a document thats already finished.

Thanks MOS

Mike

Zack Barresse
05-11-2005, 12:00 PM
Mike, FYI, I have renamed this thread to something a little more appropriate; mostly for future indexing/searching purposes. If this is not appropriate enough, we can come up with something better. :yes

MOS MASTER
05-11-2005, 12:15 PM
I want to execute this on a document thats already finished.

Thanks MOS

Mike
Hi Mike, :D

Ah ok.

You can use this sub:
Sub NoFooterLastPage()
Dim iPages As Integer

iPages = Application.ActiveDocument.BuiltInDocumentProperties(14) - 1
Application.ScreenUpdating = False

With Application.Selection
.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=iPages, Name:=""
.PageSetup.SectionStart = wdSectionNewPage
.Bookmarks("\page").Select

Application.ActiveDocument.Range(.End - 1, .End - 1).Select

.InsertBreak Type:=wdSectionBreakContinuous
.EndKey Unit:=wdStory, Extend:=wdMove

With .Sections(1).Footers(wdHeaderFooterPrimary)
.LinkToPrevious = False
.Range.Text = "Different last page"
End With
End With
End Sub


Enjoy! :whistle:

fumei
05-11-2005, 12:23 PM
OR, to be a little shorter code from Joost....
With Selection
.EndKey Unit:=wdStory
.SetRange _
Start:=aDoc.Bookmarks("\page").Range.Start - 1, _
End:=aDoc.Bookmarks("\page").Range.Start - 1
.InsertBreak Type:=wdSectionBreakNextPage
.MoveRight Unit:=wdCharacter, Count:=1
With .Sections(1).Footers.Item(1) _
.LinkToPrevious = False
.Range.Text = "" ' if you want blank
End With
End With

EricFletcher
05-11-2005, 12:27 PM
Mike

You can set this up so it is dynamic and you won't need to set the last page within a new section. Set the footer up as a conditional field like this:

{ IF {PAGE} < {DOCPROPERTY Pages} "continued on next page" " " }

This will cause the condition to be true for all but the last page so the notice will not appear on the last page. You could use the "Numpages" field instead of DOCPROPERTY but there used to be problems with it so I tend to avoid it.

In case you are not familiar with entering fields manually (vs the dialog which doesn't help much for this): use Alt-F9 to toggle the field view; Ctrl-F9 prepares an empty field with the cursor positioned within the { } braces; select and press F9 to recalculate a field.

fumei
05-11-2005, 12:28 PM
Joost? Why are you using that integer stuff???? You are using it to go to determine the number of pages then -1. Who cares how many pages there are...just go there and set the range - 1 character.

No need to declare a variable, or use DocumentProperties.

Also, it is faster to use the index number of the footer object.

wdHeaderFooterPrimary = 1
wdHeaderFooterFirstPage = 2
wdHeaderFooterEvenPage = 3

fumei
05-11-2005, 12:29 PM
Or use Eric's suggestion.

MOS MASTER
05-11-2005, 12:33 PM
Hi Gerry, :D

Excellent!

But..it leaves me with a blank page (previous) to the last!!

And look at you last with Footer block...(Line continuation character to much) :rofl:

But the code looks good so I will do a bit more testing to see what's causing the blank page...but I'm sure it's the kind of section brake your using..

First have to reply some mail..:whistle:

MOS MASTER
05-11-2005, 12:38 PM
Joost? Why are you using that integer stuff???? You are using it to go to determine the number of pages then -1. Who cares how many pages there are...just go there and set the range - 1 character.

No need to declare a variable, or use DocumentProperties.
True if you use your code but I'm just making it up as I go so code can differ from time to time! :rofl:


Also, it is faster to use the index number of the footer object.

wdHeaderFooterPrimary = 1
wdHeaderFooterFirstPage = 2
wdHeaderFooterEvenPage = 3
True..but you know I prefer readabillity above indexes. (And yes I do sinn occassionaly)

:whistle:

MOS MASTER
05-11-2005, 12:40 PM
Or use Eric's suggestion.
That's a good one forgot about this one!

We've seen it before a few weeks ago in this thread:
http://www.vbaexpress.com/forum/showthread.php?t=2236

My memory is trashy so...

It is for sure a great sollution.

:whistle:

ukemike
05-11-2005, 12:51 PM
Hi Eric,
I tried that and it does work. Its still gives me 'continued on next page' on my last page.


Im going to mess with it a little more.
Mike

MOS MASTER
05-11-2005, 12:57 PM
Example attached...:whistle:

ukemike
05-11-2005, 01:04 PM
Oh Yeah!!

Thanks guys. Awesome support. :thumb Its almost like you can charge people per minute.
Just a joke, dont get no ideas!!!

Thank you very much
Mike

MOS MASTER
05-11-2005, 01:07 PM
Hi Mike, :D

Yeah response time is excellent at this forum as well is discussion!

You're welcome and thanks to Eric for being awake! :clap:

EricFletcher
05-11-2005, 04:57 PM
Awake Joost? Actually, it was mid-afternoon here and I just stopped in to check emails and stuff as a bit of a break from fencing a field! (Kind of a mixed-mode day...)

Word's fields are often overlooked -- and MS has certainly not helped by providing sketchy help and documentation. They are a powerful tool though, and well worth studying as an alternative to VBA in quite a few instances.

MOS MASTER
05-12-2005, 09:22 AM
Awake Joost? Actually, it was mid-afternoon here and I just stopped in to check emails and stuff as a bit of a break from fencing a field! (Kind of a mixed-mode day...)
Hi Eric, :D

It was mend a figure of speech! :rofl: (but it was about late in the evening over here ... yesterday)


Word's fields are often overlooked -- and MS has certainly not helped by providing sketchy help and documentation. They are a powerful tool though, and well worth studying as an alternative to VBA in quite a few instances.
This is true of course!

In particular over here in a VBA Forum where we love our code and do overlook other potentials from time to time! (Yes I'm guilty)

Hope your field (Fencing) turned out nicely? :whistle: