VBA Word Footers - Enabling a Border

The following code extract successfully writes a new footer to a Word document:

        For Each oFooter In oSec.Footers
            If oFooter.Exists Then
                Set rngFooter = oFooter.Range
                With rngFooter
                    With .ParagraphFormat.TabStops
                        .ClearAll
                        .Add CentimetersToPoints(posAlignTabCentre), wdAlignTabCenter
                        .Add CentimetersToPoints(posAlignTabRight), wdAlignTabRight
                    End With
                    .Font.Name = "Arial"
                    .Font.Size = "10"
                    .Font.Color = wdColorDarkBlue
                    .Text = strTitle & vbTab & strVersion & vbTab & "Page "
                    .Collapse wdCollapseEnd
                    .Fields.Add rngFooter, wdFieldPage, , False
                    .Start = oFooter.Range.End
                    .Text = " of "
                    .Collapse wdCollapseEnd
                    .Fields.Add rngFooter, wdFieldNumPages, , False
                    .Start = oFooter.Range.End
                    .Text = vbCr & vbCr & strCopyright & vbTab & vbTab & strClassification
                    .Borders.Enable = True
                End With
            End If
        Next oFooter

The footer is presented as shown below. Each row in the 'table' has a border.

----------------------------------------------------------------------------------------

|  strTitle                               strVersion                             Page x of y      |

----------------------------------------------------------------------------------------

|                                                                                                             |

----------------------------------------------------------------------------------------

|  strCopyright                                                              strClassification  |

----------------------------------------------------------------------------------------

I wish to change this to show the border around the 3 'cells' in the first row only.

I have attempted to illustrate this below

----------------------------------------------------------------------------------------

|  strTitle                |               strVersion                 |            Page x of y    |

----------------------------------------------------------------------------------------

                                                                                                             

  strCopyright                                                              strClassification  

I need to change .Borders.Enable = True

How can I achieve this?

Answer
Answer

In that case Plan B, use the table for the bit with borders and text for the rest

    For Each oFooter In oSec.Footers
        If oFooter.Exists Then
            Set RngFooter = oFooter.Range
            With RngFooter
                .Style = "Footer"
                .Text = vbCr & vbCr & strCopyright & vbTab & vbTab & strClassification
                .Font.name = "Arial"
                .Font.Size = "10"
                .Font.Color = RGB(0, 0, 128)
                .Collapse wdCollapseStart
                Set oTable = RngFooter.Tables.Add(RngFooter, 1, 3)
                With oTable
                    .Range.Font.name = "Arial"
                    .Range.Font.Size = "10"
                    .Range.Font.Color = RGB(0, 0, 128)
                    .Cell(1, 1).Range.Text = strTitle
                    .Cell(1, 2).Range.Text = strVersion
                    .Cell(1, 2).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                    .Cell(1, 3).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
                    Set oCell = .Cell(1, 3).Range
                    With oCell
                        .End = .End - 1
                        .Text = "Page "
                        .Collapse wdCollapseEnd
                        .Fields.Add oCell, wdFieldPage, , False
                        .Start = oTable.Cell(1, 3).Range.End - 1
                        .Text = " of "
                        .Collapse wdCollapseEnd
                        .Fields.Add oCell, wdFieldNumPages, , False
                    End With
                    With .Rows(1)
                        With .Borders(wdBorderTop)
                            .LineStyle = Options.DefaultBorderLineStyle
                            .LineWidth = Options.DefaultBorderLineWidth
                            .Color = RGB(0, 0, 128)
                        End With
                        With .Borders(wdBorderLeft)
                            .LineStyle = Options.DefaultBorderLineStyle
                            .LineWidth = Options.DefaultBorderLineWidth
                            .Color = RGB(0, 0, 128)
                        End With
                        With .Borders(wdBorderBottom)
                            .LineStyle = Options.DefaultBorderLineStyle
                            .LineWidth = Options.DefaultBorderLineWidth
                            .Color = RGB(0, 0, 128)
                        End With
                        With .Borders(wdBorderRight)
                            .LineStyle = Options.DefaultBorderLineStyle
                            .LineWidth = Options.DefaultBorderLineWidth
                            .Color = RGB(0, 0, 128)
                        End With
                        With .Borders(wdBorderVertical)
                            .LineStyle = Options.DefaultBorderLineStyle
                            .LineWidth = Options.DefaultBorderLineWidth
                            .Color = RGB(0, 0, 128)
                        End With
                    End With
                End With
            End With
        End If
    Next oFooter

Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 345 Applies to: