Tabs


Tab Stops Collection

A tab stop object represents a tab stop
A tab stops collection is a collection of all the tabs stop objects.
Each of the Paragraph, ParagraphFormat and Paragraphs objects have a TabStops property which returns a tabstops collection.
The TabStops collection represents the custom and default tabs for a paragraph or group of paragraphs.
Tab stops are indexed numerically from left to right along the ruler.


Dim objTabStopsCol As TabStops 

Dim objTabStop As TabStop 
For Each objTabStop In Selection.Paragraphs.TabStops
      objTabStop.Position
Next aTab

When working with the Paragraphs collection (or a range with several paragraphs), you must modify each paragraph in the collection individually if the tab stops aren't identical in all the paragraphs.

Dim objParagraph As Paragraph 
For Each objParagraph In ActiveDocument.Content.Paragraphs
    objParagraph.TabStops(InchesToPoints(1)).Clear
Next para


Adding Tabs

Use the Add method to add a tab stop.

objTabStopsCol.Add Position:=InchesToPoints(1), _ 
                   Alignment:=wdTabAlignment.wdAlignTabLeft, _
                   Leader:=wdTabLeader.wdTabLeaderSpaces

You can also add a tab by specifying the location with the TabStops property

Selection.Paragraphs.TabStops(InchesToPoints(2)).Alignment = wdTabAlignment.wdAlignTabLeft 

This is equivalent to the following line:

Selection.Paragraphs.TabStops.Add Position:=InchesToPoints(2), _ 
                                  Alignment:=wdTabAlignment.wdAlignTabLeft

This adds a tab stop positioned at 2.5 inches to the selected paragraphs and then displays the position of each item in the TabStops collection.

Selection.Paragraphs.TabStops.Add Position:=InchesToPoints(2.5) 

This adds a tab stop that is a left-aligned tab with a dotted tab leader positioned at 1 inch (72 points).

Selection.Paragraphs.TabStops.Add Position:=InchesToPoints(1), _ 
                                  Leader:=wdTabLeader.wdTabLeaderDots, _
                                  Alignment:=wdTabAlignment.wdAlignTabLeft

This adds a tab that is centred and is positioned at 2 inches.

Selection.Paragraphs.TabStops.Add Position:=InchesToPoints(2), _ 
                                  Alignment:=wdTabAlignment.wdAlignTabCenter

This adds a tab for every paragraph in the active document

ActiveDocument.Content.ParagraphFormat.TabStops.Add Position:=InchesToPoints(1), _ 
                                                    Alignment:=wdTabAlignment.wdAlignTabLeft


Removing Tabs

This removes the first custom tab stop from the first paragraph in the active document.

ActiveDocument.Paragraphs(1).TabStops(1).Clear 


Removing all Tab Stops

This removes all the tabs from the whole document

ActiveDocument.Content.ParagraphFormat.TabStops.ClearAll 

objTabStopsCol.ClearAll 


Changing the Default Tab Stop Size

To change the default tab stop you must use the DefaultTabStop property of the Document object.

ActiveDocument.DefaultTabStop = InchesToPoints(1) 
objDocument.DefaultTabStop = InchesToPoints(0.5)

To locate the nearest tab stop object (i.e. the nearest tab)

objTabStopsCol.Before Position:= 
objTabStopsCol.After Position:=


Word removes all default tab stops whose positions lie to the left of a custom tab stop

objTabStop.Alignment 
objTabStop.Clear
objTabStop.CustomTab = True | False
objTabStop.Leader
objTabStop.Previous | Next
objTabStop.Position

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrev