Replace Indents with Tabs macro
:
Return to List
Public Sub Main()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.WholeStory
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ExtendMode = False
Selection.HomeKey Unit:=wdStory
On Error GoTo BYE
Count = 0
OUTERLOOP:
ActiveDocument.Bookmarks.Add Name:="Pt1"
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove
Selection.HomeKey Unit:=wdLine, Extend:=wdMove
ActiveDocument.Bookmarks.Add Name:="Pt2"
Address1 = ActiveDocument.Bookmarks("Pt1").Range.START
Address2 = ActiveDocument.Bookmarks("Pt2").Range.START
If Address1 = Address2 Then GoTo BYE
Align = Selection.Paragraphs.Alignment ' MsgBox ("The paragraph alignment is " + Str(Align))
If Align = 1 Then GoTo OUTERLOOP 'To ignore centered paragraphs.
Ps = Selection.Information(5)
If Ps <> 0 Then
Selection.ParagraphFormat.FirstLineIndent = InchesToPoints(0)
Selection.ParagraphFormat.LeftIndent = InchesToPoints(0)
Count = Count + 1
TabNum = Ps / 36
If TabNum = 1 Then
Selection.InsertAfter Text:=Chr(9)
ElseIf TabNum = 2 Then
Selection.InsertAfter Text:=Chr(9) + Chr(9)
ElseIf TabNum = 3 Then
Selection.InsertAfter Text:=Chr(9) + Chr(9) + Chr(9)
ElseIf TabNum = 4 Then
Selection.InsertAfter Text:=Chr(9) + Chr(9) + Chr(9) + Chr(9)
ElseIf TabNum = 5 Then
Selection.InsertAfter Text:=Chr(9) + Chr(9) + Chr(9) + Chr(9) + Chr(9)
ElseIf TabNum = 6 Then
Selection.InsertAfter Text:=Chr(9) + Chr(9) + Chr(9) + Chr(9) + Chr(9) + Chr(9)
ElseIf TabNum = 7 Then
Selection.InsertAfter Text:=Chr(9) + Chr(9) + Chr(9) + Chr(9) + Chr(9) + Chr(9) + Chr(9)
ElseIf TabNum > 7 Then
Btn = MsgBox("More than 7 tabs must be inserted manually. Do you wish to stop & do this?", vbYesNo)
If Btn = vbYes Then GoTo BYE
End If
Selection.ExtendMode = False
Selection.MoveRight Unit:=wdCharacter, Count:=1
GoTo OUTERLOOP
Else
GoTo OUTERLOOP
End If
BYE:
Selection.ExtendMode = False
Selection.HomeKey Unit:=wdStory
MsgBox ("There were" + Str(Count) + " indents replaced with tabs.")
End Sub
Note to Webmaster