View Single Post
  #2   Report Post  
Shauna Kelly
 
Posts: n/a
Default

Hi Bob

Try something like the following:

Option Explicit

Sub DeleteTextBetweenTabs()

Dim oRange As Word.Range
Dim nHowFarToTheNextTab As Long

'Purpose: Find a tab, and delete all text
'between it and the next tab.
'
'User needs to click in the text
'before the first
'tab, and then run this macro.

'Collapse the selection
Selection.Collapse wdCollapseEnd

With Selection.Find
'Find the first tab
.ClearAllFuzzyOptions
.ClearFormatting
.Text = vbTab
.Format = False
.Forward = True
.Wrap = wdFindStop
.Execute

If .Found Then
Set oRange = Selection.Range

'We want the text *between* tabs, so
'move one character past the tab
oRange.Move Unit:=wdCharacter, Count:=1

'Extend the range to the next tab.
nHowFarToTheNextTab = oRange.MoveEndUntil _
(cset:=vbTab, Count:=wdForward)

If nHowFarToTheNextTab 0 Then
'If there was a second tab to find, then
'oRange now spans the text between the two tabs.

'Following line is for testing. Remove for real life.
oRange.HighlightColorIndex = wdBlue

'Following is the real-life line. Remove the quote
'mark at the beginning of the line to activate it.
'oRange.Delete

'Position the cursor just after the range
oRange.Collapse wdCollapseEnd
oRange.Select
Else
MsgBox "We couldn't find a second tab"
End If
Else
MsgBox "No tabs found"
End If

End With
End Sub


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


"InOverMyHead" wrote in message
...
I want to "select" everything between two tabs. This will be one step in my
little macro, afterwhich I delete the selected text. But how do I do it? I
can "Find" - Tab - but then I need to turn on Select then Find the second
tab. How do I turn on Select?

Any help would be greatly appreciated. (PS: I'm using Word 2000)

Bob