Thread: [Solved] Macro to delete tabs in Word
View Single Post
 
Old 12-16-2020, 04:07 PM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Paul's method will work and be very fast for the specific example you gave. If you want a macro that simply deletes all but the first tab in each paragraph of text, you could use:


Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oPar As Paragraph
Dim oRng As Range
Dim lngIndex As Long
  For Each oPar In ActiveDocument.Range.Paragraphs
    lngIndex = 0
    Set oRng = oPar.Range
    With oRng.Find
      .Text = Chr(9)
      While .Execute
        oRng.Select
        lngIndex = lngIndex + 1
        If lngIndex > 1 Then
          oRng.Text = " "
          oRng.Collapse wdCollapseEnd
        End If
      Wend
    End With
  Next oPar
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote