Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2018, 11:56 AM
ksor ksor is offline PAGE and NUMPAGES fields in footer ?? Windows 10 PAGE and NUMPAGES fields in footer ?? Office 2016
Advanced Beginner
PAGE and NUMPAGES fields in footer ??
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 74
ksor is on a distinguished road
Default PAGE and NUMPAGES fields in footer ??

I made this short method to setup a header/footer in a word document:



Code:
Public Sub headerFooter(f As Form, bD As Word.Document)
    With bD.Sections(1)
        .Headers(wdHeaderFooterPrimary).Range.Text = "Alle registrerede data vedr. PersonId: " & f.PersonID & " " & HentFMENavn(f.PersonID)
        .Footers(wdHeaderFooterPrimary).Range.Text = "Sammensat " & StrConv(Format(Date, "dddd"), vbProperCase) & " den " & Date & vbTab & vbTab & "Side "
        .Footers(wdHeaderFooterPrimary).Range.Fields.add Selection.Range, wdFieldEmpty, "PAGE  ", True
        .Footers(wdHeaderFooterPrimary).Range.Text = " af "
        .Footers(wdHeaderFooterPrimary).Range.Fields.add Selection.Range, wdFieldEmpty, "NUMPAGES  ", True
    End With
End Sub
BUT the actual digits for the fields PAGE and NUMPAGES is NOT writen in the footer - they are writen in the normal text area !

What do I need to change in the code ?

EDIT: Now I see I should have posted in WORD VBA - sorry !
Reply With Quote
  #2  
Old 02-02-2018, 01:29 PM
macropod's Avatar
macropod macropod is offline PAGE and NUMPAGES fields in footer ?? Windows 7 64bit PAGE and NUMPAGES fields in footer ?? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I'd be surprised if any of the footer content was correct with that code - as posted all you'd end up with in the footer is ' af ', since:
Code:
.Footers(wdHeaderFooterPrimary).Range.Text = " af "
overwrites whatever is already there and:
Code:
.Footers(wdHeaderFooterPrimary).Range.Fields.add Selection.Range
adds the field to whatever is selected - which is probably not in the footer.

Try:
Code:
Public Sub headerFooter(f As Form, bD As Word.Document)
    With bD.Sections(1)
        .Headers(wdHeaderFooterPrimary).Range.Text = "Alle registrerede data vedr. PersonId: " & f.PersonID & " " & HentFMENavn(f.PersonID)
        With .Footers(wdHeaderFooterPrimary).Range
            .Text = "Sammensat " & StrConv(Format(Date, "dddd"), vbProperCase) & " den " & Date & vbTab & vbTab & "Side "
            .Fields.Add .Characters.Last, wdFieldEmpty, "PAGE", False
            .InsertAfter " af "
            .Fields.Add .Characters.Last, wdFieldEmpty, "NUMPAGES", False
        End With
    End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-02-2018, 07:56 PM
Charles Kenyon Charles Kenyon is offline PAGE and NUMPAGES fields in footer ?? Windows 10 PAGE and NUMPAGES fields in footer ?? Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I would strongly urge you to consider using a Template or Header AutoText/ Building Block for this. IMO, it is much easier to fine-tune.

This recommendation may speak to my (lack of) vba coding skills. However, I have long found use of built-in capabilities of Word to be superior to coding when both can produce the same result. It may well be that you need to do it as part of a longer procedure. However, creating a document through code rather than using a template seems like an exercise in frustration.
Reply With Quote
  #4  
Old 02-02-2018, 10:14 PM
ksor ksor is offline PAGE and NUMPAGES fields in footer ?? Windows 10 PAGE and NUMPAGES fields in footer ?? Office 2016
Advanced Beginner
PAGE and NUMPAGES fields in footer ??
 
Join Date: Feb 2018
Location: Århus V, Denmark
Posts: 74
ksor is on a distinguished road
Default

it is working nicely

thx !
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
I have 20 page word document with a footer. Can i change page # 10 footer only? aligahk06 Word 2 10-25-2017 04:53 AM
PAGE and NUMPAGES fields in footer ?? Showing "page of numpages" and "sectionpage of sectionpages" RobH Word 2 02-14-2016 04:12 PM
PAGE and NUMPAGES fields in footer ?? begin each section with page 1 in header PLUS continuous page numbering in footer onemorecupofcoffee Word 18 09-04-2013 04:31 PM
Need help with quickparts(fields) in footer Nighthawk Word 2 08-22-2012 05:13 AM
PAGE and NUMPAGES fields in footer ?? Use NUMPAGES in formulae Friedebarth Word 1 11-30-2011 02:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft