Consulting

Results 1 to 3 of 3

Thread: Code to delete extra tabs in paragraph.

  1. #1

    Code to delete extra tabs in paragraph.

    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.

  2. #2
    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

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •