Results 1 to 3 of 3

Thread: How to left and right justify elements in a footer range?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    You are right about the offending code. You need to set the positions of the tab stops (or you could simply apply the default Footer style which already has the tab stops) before changing the font and inserting the text. However the following should work:

    Sub PageNosFileNameAdd_Footer()
    '   add page number and name to footer
    Dim rngFooter As Range
    Dim currDoc As Word.Document
    
        Set currDoc = Application.ActiveDocument
        currDoc.PageSetup.OddAndEvenPagesHeaderFooter = False
        Set rngFooter = currDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
        With rngFooter
            .Text = ""        ' Delete any existing page number
            .Fields.Add rngFooter, wdFieldPage
            .Collapse wdCollapseEnd
            .Text = vbTab & vbTab & removeExtension(currDoc.name)
        End With
        Set rngFooter = currDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
        rngFooter.Font.name = "IndUni-T"
        rngFooter.Font.Size = 9
        SetFooterTabs currDoc, rngFooter
        currDoc.Activate
        currDoc.UndoClear
        DoEvents
        Set rngFooter = Nothing
        Set currDoc = Nothing
    End Sub
    
    Sub SetFooterTabs(oDoc As Document, orng As Range)
    Dim lngCenter As Long
    Dim lngRight As Long
        lngCenter = (oDoc.PageSetup.PageWidth _
                     - oDoc.PageSetup.LeftMargin _
                     - oDoc.PageSetup.RightMargin) / 2
        lngRight = oDoc.PageSetup.PageWidth _
                   - oDoc.PageSetup.LeftMargin _
                   - oDoc.PageSetup.RightMargin
        'MsgBox PointsToCentimeters(lngCenter) & vbCr & PointsToCentimeters(lngRight)
        orng.ParagraphFormat.TabStops.ClearAll
        orng.ParagraphFormat.TabStops.Add _
                Position:=lngCenter, _
                Alignment:=wdAlignTabCenter, _
                Leader:=wdTabLeaderSpaces
        orng.ParagraphFormat.TabStops.Add _
                Position:=lngRight, _
                Alignment:=wdAlignTabRight, _
                Leader:=wdTabLeaderSpaces
    End Sub
    Last edited by gmayor; 01-05-2015 at 06:47 AM.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •