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. #1

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

    I have a routine that adds the page number and filename to a footer. The page number is left-justified (that works), but I am unable to persuade the filename to be right aligned by setting the appropriate tab stop. Presently I have to adjust the filename position manually when the macro has run. The offending code is (I imagine):

    rngFooter.Paragraphs.TabStops.ClearAll
        rngFooter.Paragraphs.TabStops.Add wdAlignTabLeft, wdAlignTabRight
    What should it be to left justify the page number and right justify the filename? Maybe I need to add the tab positions, but the routine is called by a variety of other routines, and the margin sizes will differ from call to call, so setting absolute tab stop positions will not work.

    Full routine is below.

    Thanks

    John Davidson


    Sub PageNosFileNameAdd_Footer()
    '   add page number and name to footer
    
    
        Dim rngFooter As Range
        Dim currDoc As Word.Document
        Dim field As field
    
    
        Set currDoc = Application.ActiveDocument
        
        currDoc.PageSetup.OddAndEvenPagesHeaderFooter = False
        Set rngFooter = currDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
    
    
        For Each field In rngFooter.Fields
            field.Delete            ' Remove existing fields
        Next
    
    
        rngFooter.Font.Name = "IndUni-T"
        rngFooter.Font.Size = 9  
        rngFooter.Paragraphs.TabStops.ClearAll
        rngFooter.Paragraphs.TabStops.Add wdAlignTabLeft, wdAlignTabRight
        
        rngFooter.Text = ""                             ' Delete any existing page number
        rngFooter.Fields.Add rngFooter, wdFieldPage
          
        rngFooter.Collapse wdCollapseEnd
        rngFooter.Text = vbTab & vbTab & removeExtension(currDoc.Name)
        
        currDoc.Activate
        currDoc.UndoClear
        DoEvents
    
    
    End Sub
    
    
    Private Function removeExtension(p_strFilename As String) As String
        Dim nPosn As Long
    
    
        nPosn = InStrRev(p_strFilename, ".")
        If nPosn > 0 Then
            removeExtension = Left(p_strFilename, nPosn - 1)
        Else
            removeExtension = p_strFilename
        End If
    
    
    End Function
    Last edited by johndavidson; 01-05-2015 at 05:11 AM.

Posting Permissions

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