View Single Post
 
Old 12-13-2023, 03:13 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

When you say it doesn't fulfill your requirement, can you explain what it wasn't doing?

I can see you only touch the primary footer without seeing if the other two footers are turned on. Nor are you looking at link to previous settings. positionfrombottom is created as a variable but not used. The actual location of the text in the footer will depend on the setting for footer distance + paragraph space after + a bit of the line spacing mixed with the typeface and font size.

I normally do this sort of thing by first storing my preferred footer as a building block and then using a macro to insert that building block wherever I want it.

So assuming you have created a footer exactly how you want it, and then saved that as a building block in your Normal template with the name myFoot, you could then use this code
Code:
Sub AddFooterWithPageNumber()
  Dim aSect As section, aFoot As HeaderFooter
  For Each aSect In ActiveDocument.Sections       ' Loop through each section in the document
    aSect.PageSetup.FooterDistance = CentimetersToPoints(1)
    Set aFoot = aSect.Footers(wdHeaderFooterPrimary)
    If Not aFoot.LinkToPrevious Then
      NormalTemplate.BuildingBlockEntries("myFoot").Insert Where:=aFoot.Range, RichText:=True
      aFoot.Range.Paragraphs.Last.Range.Delete
    End If
  Next aSect
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote