PDA

View Full Version : [SOLVED:] Code to delete extra tabs in paragraph.



lkpederson
03-29-2014, 12:46 PM
Issue: Delete all but ONE tab in a line.

Text looks something like this:
blah blah blah <tab> blah blah blah. <LF>
blah blah blah <tab> <tab> <tab> blah blah blah. <LF>
blah blah <tab> <tab> blah blah. <LF>

End result to look like:
blah blah blah <tab> blah blah blah. <LF>
blah blah blah <tab> blah blah blah. <LF>
blah blah <tab> blah blah. <LF>

Lines are delimited by hard returns. Document is quite small, typically no more than two pages.

Thanks.

lkpederson
03-29-2014, 01:22 PM
Sorted it out...found this and tweaked it.

Dim found As Boolean
With o.Content.Find
.Text = vbTab & vbTab
.Wrap = wdFindContinue
found = .Execute
End With
While found
With o.Content.Find
.Text = vbTab & vbTab
.Replacement.Text = vbTab
found = .Execute(Replace:=wdReplaceAll)
End With
Wend

macropod
03-29-2014, 07:11 PM
You don't need a macro for this - you can do it with a wildcard Find/Replace, where:
Find = [^t]{2,}
Replace = ^t
Run once, it will reduce all multi-tab sequences to single tabs. You could, of course, record the above as a macro.