Reply
 
Thread Tools Display Modes
  #1   Report Post  
InOverMyHead
 
Posts: n/a
Default Select Tool in Macro ??

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


  #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





  #3   Report Post  
Greg
 
Posts: n/a
Default

Bob,

You don't really need to select the text to delete it. Here is a macro
that finds text between the first and second tabs following the
insertion point and deletes the text while leaving the tabs.

Sub DeleteTextBetweenTabs()
Dim myRange As Range
Set myRange = Selection.Range
myRange.End = ActiveDocument.Range.End
With myRange.Find
.ClearFormatting
.MatchWildcards = True
.Text = "^t" & "*" & "^t"
.Execute
myRange.Start = myRange.Start + 1
myRange.End = myRange.End - 1
myRange.Delete
End With
End Sub

  #4   Report Post  
InOverMyHead
 
Posts: n/a
Default


"Greg" wrote in message
oups.com...
Bob,

You don't really need to select the text to delete it. Here is a macro
that finds text between the first and second tabs following the
insertion point and deletes the text while leaving the tabs.

Sub DeleteTextBetweenTabs()
Dim myRange As Range
Set myRange = Selection.Range
myRange.End = ActiveDocument.Range.End
With myRange.Find
.ClearFormatting
.MatchWildcards = True
.Text = "^t" & "*" & "^t"
.Execute
myRange.Start = myRange.Start + 1
myRange.End = myRange.End - 1
myRange.Delete
End With
End Sub


Thanks for the responses! But it sure sounds more complicated than it otta
be!!?!! . (And to think that in WordPerfect all I had to do was hit one key
for "Select"!!) Let's assume for the moment - just for the sake of this
discussion - that I don't do programming, that I am a newbie (note newsgroup
name) and I expect the Macro function to simply record keystrokes - then
play them back on command. From the responses, may I conclude I'm outa luck
on the delete-between-tabs routine, and that this is beyond the ability of
Bill's programmers to build into this product?

(In fact, I would use variations of the delete-between-tabs routine often,
but each time it would use different from-to points. And I sure don't want
to have to write a program for every macro I use.)

Bob





  #5   Report Post  
Klaus Linke
 
Posts: n/a
Default

Hi Bob,

Hmm... Professional Word users will tell you to avoid tabs altogether.
Then why should Word offer a special built-in function to delete stuff =
between two tabs?

BTW, you can delete the stuff between the next two tabs with =
Find/Replace, similar to the macro Greg posted:
Edit Replace, check "Match wildcards",
Find what: (^t)[!^13]@(^t)
Replace with: \1\2
You can use the macro recorder to create a macro from this without =
writing a line of code.

If you have a "table" done with tabs, you can also use =
Alt+LeftMouseButton+Drag to select a "column" and delete it.

Greetings,
Klaus


"InOverMyHead" schrieb im Newsbeitrag =
...
=20
"Greg" wrote in message
oups.com...
Bob,

You don't really need to select the text to delete it. Here is a =

macro
that finds text between the first and second tabs following the
insertion point and deletes the text while leaving the tabs.

Sub DeleteTextBetweenTabs()
Dim myRange As Range
Set myRange =3D Selection.Range
myRange.End =3D ActiveDocument.Range.End
With myRange.Find
.ClearFormatting
.MatchWildcards =3D True
.Text =3D "^t" & "*" & "^t"
.Execute
myRange.Start =3D myRange.Start + 1
myRange.End =3D myRange.End - 1
myRange.Delete
End With
End Sub

=20
Thanks for the responses! But it sure sounds more complicated than it =

otta
be!!?!! . (And to think that in WordPerfect all I had to do was hit =

one key
for "Select"!!) Let's assume for the moment - just for the sake of =

this
discussion - that I don't do programming, that I am a newbie (note =

newsgroup
name) and I expect the Macro function to simply record keystrokes - =

then
play them back on command. From the responses, may I conclude I'm outa =

luck
on the delete-between-tabs routine, and that this is beyond the =

ability of
Bill's programmers to build into this product?
=20
(In fact, I would use variations of the delete-between-tabs routine =

often,
but each time it would use different from-to points. And I sure don't =

want
to have to write a program for every macro I use.)
=20
Bob



  #6   Report Post  
InOverMyHead
 
Posts: n/a
Default

Thanks loads!! BTW - Its not my choice to use tabs - I'm trying to get rid
of them, actually. They often arise in tab delimited files as you no doubt
know. AND I'm not looking to delete text between tabs - that was just an
example. I want to be able to delete text between "Here" (current curser
location) (and probably result of a Find action) and "There" (text string
xxx for example) (and result of another Find action). I was trying macros
(this operation must repeat hundreds of times in a long document) but it
doesn't seem to be able to "Select" and delete like I would expect. Now
comes Klaus with a most reasonable idea - use find and replace! Duh - I
don't know why I didn't think of this! I tried the example and it didn't
work immediately, but it sure gave me some ideas - so I now just do Find -
^t*^t and replace with [blank]. Seems to work, but am I missing something
by not using all those swear words ((^t)[!^13]@(^t)\1\2)??

Thanks again! (Wowser - there's a lot more power in the search&replace than
I had noticed!!)

Bob



"Klaus Linke" wrote in message
...
Hi Bob,

Hmm... Professional Word users will tell you to avoid tabs altogether.
Then why should Word offer a special built-in function to delete stuff
between two tabs?

BTW, you can delete the stuff between the next two tabs with Find/Replace,
similar to the macro Greg posted:
Edit Replace, check "Match wildcards",
Find what: (^t)[!^13]@(^t)
Replace with: \1\2
You can use the macro recorder to create a macro from this without writing a
line of code.

If you have a "table" done with tabs, you can also use
Alt+LeftMouseButton+Drag to select a "column" and delete it.

Greetings,
Klaus


"InOverMyHead" schrieb im Newsbeitrag
...

"Greg" wrote in message
oups.com...
Bob,

You don't really need to select the text to delete it. Here is a macro
that finds text between the first and second tabs following the
insertion point and deletes the text while leaving the tabs.

Sub DeleteTextBetweenTabs()
Dim myRange As Range
Set myRange = Selection.Range
myRange.End = ActiveDocument.Range.End
With myRange.Find
.ClearFormatting
.MatchWildcards = True
.Text = "^t" & "*" & "^t"
.Execute
myRange.Start = myRange.Start + 1
myRange.End = myRange.End - 1
myRange.Delete
End With
End Sub


Thanks for the responses! But it sure sounds more complicated than it otta
be!!?!! . (And to think that in WordPerfect all I had to do was hit one

key
for "Select"!!) Let's assume for the moment - just for the sake of this
discussion - that I don't do programming, that I am a newbie (note

newsgroup
name) and I expect the Macro function to simply record keystrokes - then
play them back on command. From the responses, may I conclude I'm outa

luck
on the delete-between-tabs routine, and that this is beyond the ability of
Bill's programmers to build into this product?

(In fact, I would use variations of the delete-between-tabs routine often,
but each time it would use different from-to points. And I sure don't

want
to have to write a program for every macro I use.)

Bob



  #7   Report Post  
Greg
 
Posts: n/a
Default

Bob,

If it performs like you expect then you are not missing anything :-)

All those swear words have a purpose. Klaus assumed, as did I, that
you wanted to keep the tabs and delete the text in between. Klaus also
assumed that you would want to limit the found range to a paragraph and
not delete the text say between the first and only tab in paragraph 1
and the first tab in paragraph 2.

Here is want the curse words are saying:

(1) Find a group consisting of a tab
[!13]@ find every possible following character except a paragraph mark
1 or more times
(2) Find a group consisting of a tab.

The
\1\2 in the Replace with tells word to remove all the muck it found and
replace it with the content of groups 1 and 2.

If you are up to some really foul literature, see fellow MVP Graham
Mayors:
http://www.gmayor.com/replace_using_wildcards.htm

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table in a Form HiDbLevel Tables 12 February 27th 06 12:59 PM
Possible bug when recording a Word Macro Raven95 Microsoft Word Help 4 April 30th 05 09:49 PM
Running document macro from server Intravler New Users 0 March 4th 05 04:33 AM
Save As is not working due to macro security settings Craig Meritz Microsoft Word Help 1 December 16th 04 03:53 AM
2000 to 2002 macro and "Could not open macro storage" Art Farrell Mailmerge 1 December 6th 04 12:40 PM


All times are GMT +1. The time now is 02:41 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"