Word selection
Posted
by Brian Sturk
on August 24th, 1998
Sub WordSelect()
'DESCRIPTION: Selects a word like a double click with mouse
'Very handy for keyboard users. Not the prettiest
'or quickest (I heard BASIC was slow! :] )
'macro but it works better than the built in word right after Alt-M or
'C in BRIEF, etc and more accurate, also helps RSI sufferers like me.
'
'Valid characters are all upper case and lower case letters
'and the underscore "_" character, to change this behav add toLegalChars.
'
'Rev 1 - Got it working without checking for individual chars
' instead used the numerical comparisons
'
'Rev 2 - Added numbers to be valid during string search
' Now supports all valid C/C++ chars duh!
'
'Rev 3 - (7/12/98) Added check for first column, also tidy'd
' up code for checking for valid letters from ranges
' to using InStr w/ valid chars (Thanks David Cotton)
' BTW I never claimed to be a VB guy! :)
'
'This insignificant macro was written by B.Sturk on Aug 31 1997
'If you find an easier way to accomplish what this macro
'does or a quicker way, or a bug, please let me know!
'email: bsturk@nh.ultranet.com
'http://www.nh.ultranet.com/~bsturk
iCount =0
LegalChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
ExecuteCommand "SelectChar" 'start char selection (not in loop)
ActiveDocument.Selection.CharLeft dsExtend
cSelect = ActiveDocument.Selection
do while InStr(LegalChars, cSelect) <> 0
iCurrentCol = ActiveDocument.Selection.CurrentColumn
If iCurrentCol = 1 Then
iCount = iCount + 1
Exit Do
End if
iCount = iCount + 1
ExecuteCommand "SelectChar"
ExecuteCommand "SelectChar"
ActiveDocument.Selection.CharLeft dsExtend 'move to next char
cSelect = ActiveDocument.Selection
Loop
' Now that we're done moving left and checking we need to go to the beginning
' of the word to move right and check for legal chars. If we're in column 1 we're at the
' beginning
If iCurrentCol <> 1 Then
ActiveDocument.Selection.CharRight 1 'move to beginning of word
End if
'no need to check stuff twice, move to starting point and go check right side
if iCount <> 0 Then ' in case we start at beginning of word
ActiveDocument.Selection.CharRight dsMove, iCount
End if
'check to the right of the cursor placement
ExecuteCommand "SelectChar"
ExecuteCommand "SelectChar"
ActiveDocument.Selection.CharRight dsExtend
cSelect = ActiveDocument.Selection
do while InStr(LegalChars, cSelect) <> 0
iCount = iCount + 1
ExecuteCommand "SelectChar"
ExecuteCommand "SelectChar"
ActiveDocument.Selection.CharRight dsExtend
cSelect = ActiveDocument.Selection
Loop
'stop char select mode, move left one, and select entire word
ExecuteCommand "SelectChar"
ActiveDocument.Selection.CharLeft dsMove, 1 ' We've overstepped by one move back
ExecuteCommand "SelectChar"
ActiveDocument.Selection.CharLeft dsExtend, iCount
End Sub

Comments
Here is my attempt at word selection
Posted by Legacy on 08/29/2001 12:00amOriginally posted by: Ender Wiggin
Replyshift+ctrl works too..
Posted by Legacy on 08/03/2000 12:00amOriginally posted by: Anders Montonen
Hold down SHIFT for selection, CTRL for word hopping and press RIGHT arrow. Of course, if the caret is in the middle of a word, you might have to press CTRL+LEFT first.
Of course, using macros is chest-hair-growing, but a bit unnecessary in this case..
Reply
Great stuff!!! Thanks.
Posted by Legacy on 10/07/1999 12:00amOriginally posted by: Luis Garcia
Great stuff!!! Thanks.
ReplyGreat! I was missing this for years. Here a fix for VC6
Posted by Legacy on 04/07/1999 12:00amOriginally posted by: wech
Reply