View Single Post
 
Old 02-24-2014, 09:44 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try something along the following lines:
Code:
Sub Demo()
Application.ScreenUpdating = True
Dim i As Long
With Selection
  For i = 1 To .Paragraphs.Count
    With .Paragraphs(i).Range.Characters.First
      Select Case Int(PointsToInches(.Information(wdHorizontalPositionRelativeToTextBoundary)) * 4)
        Case 1: .InsertBefore vbTab
        Case 2: .InsertBefore vbTab & vbTab
        Case 3: .InsertBefore vbTab & vbTab & vbTab
        Case 4: .InsertBefore vbTab & vbTab & vbTab & vbTab
        Case 5: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab
        Case 6: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab & vbTab
        Case 7: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab
        Case 8: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab
        Case 9: .InsertBefore vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab
      End Select
    End With
  Next
  .ParagraphFormat.Alignment = wdAlignParagraphLeft
  .ClearParagraphAllFormatting
End With
Application.ScreenUpdating = True
End Sub
or:
Code:
Sub Demo()
Application.ScreenUpdating = True
Dim i As Long, j As Long, StrTmp As String
With Selection
  For i = 1 To .Paragraphs.Count
    StrTmp = vbNullString
    With .Paragraphs(i).Range.Characters.First
      For j = 0 To Int(PointsToInches(.Information(wdHorizontalPositionRelativeToTextBoundary)) * 4)
        StrTmp = StrTmp & vbTab
      Next
      .InsertBefore StrTmp
    End With
  Next
  .ParagraphFormat.Alignment = wdAlignParagraphLeft
  .ClearParagraphAllFormatting
End With
Application.ScreenUpdating = True
End Sub
As coded, the macros apply tabs to a selected block of text. You may need to play around with the '* 4' and even subtract a constant value from than line to get the kind of indenting you desire. I'd suggest going even further: Define a 'code' Style with whatever final tab-stop positions you'd prefer and apply that to the range after the '.ClearParagraphAllFormatting' line. The second macro is more flexible, as it accommodates any level of indenting.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 02-24-2014 at 09:49 PM. Reason: Alternative macro
Reply With Quote