Thursday, September 8, 2011

Add tabs to centre of text area and right margin



The following macro sets a centre aligned tab, centred between the current margins, and a right aligned tab at the right margin.
Sub AddTabs()
Dim iLeft As Long
Dim
iRight As Long
Dim
iCentre As Long
Dim
iWidth As Long
With
Selection
     iLeft = .Sections(1).PageSetup.LeftMargin
     iRight = .Sections(1).PageSetup.RightMargin
     iWidth = .Sections(1).PageSetup.PageWidth
     iCentre = (iWidth - iLeft - iRight) / 2
     .ParagraphFormat.TabStops.Add Position:=iCentre, _
        Alignment:=wdAlignTabCenter, _

        Leader:=wdTabLeaderSpaces
     .ParagraphFormat.TabStops.Add Position:=iWidth - (iRight + iLeft), _
        Alignment:=wdAlignTabRight, _
        Leader:=wdTabLeaderSpaces
End With
End Sub


No comments:

Post a Comment