Consider underscore as part of the word in double click selection

M

malix0

When I double click to select a word I want that underscore will be
selected and not considered as a separator. If I double click on
the_word_with_underscore I want to select entire phrase includin
underscore and n ot only single word. I try to write this macro:

I create a class clsWordClass:

Public WithEvents appWord As Word.Application

Private Sub appWord_WindowBeforeDoubleClick(ByVal Sel As Selection,
Cancel As Boolean)
test
End Sub


and a module basGeneral

Dim objClass As New clsWordApp

Sub Register_EventHandler()
Set objClass.appWord = Word.Application
End Sub

Sub test()
c = ActiveDocument.Characters(Selection.End + 1)
If ActiveDocument.Characters(Selection.Words.First.End + 1) = "_"
Then
'Selection.End = Selection.End + 1
Selection.Start = Selection.Words.First.Start
Selection.End = Selection.Words.First.End + 1
MsgBox Selection.Text
End If
End Sub
------------------------------------------------


Then when I double click on a word the underscore get selected and the
MsgBox show a word that includes the underscore, but after only the
word without underscore remains selected. It will be possible with an
event like WindowAfterDoubleClick, but this does not exixts.
 
H

Helmut Weber

Hi Malix,

in case the selection is in the first word of the phrase:

Sub Test4abc()
Dim rTmp As Range
Set rTmp = Selection.Range
rTmp.start = rTmp.Words(1).start
While rTmp.Words.Last.Characters.Last.Next = "_"
rTmp.End = rTmp.Words.Last.End + 2
rTmp.End = rTmp.Words.Last.End
Wend
If rTmp.Characters.Last = " " Then
rTmp.End = rTmp.End - 1
End If
rTmp.Select
End Sub

I didn't care about event-handling,
as that seems not to be the problem.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top