View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default set textbox cursor in mouse right-click

Hi Bart,

This seemed to work for me with no more testing than shown below. Not sure
about other implications, eg might want to flag and early exit other Textbox
events.

Private Declare Sub mouse_event Lib "user32" ( _
ByVal dwFlags As Long, ByVal dX As Long, _
ByVal dY As Long, ByVal dwData As Long, _
ByVal dwExtraInfo As Long)

Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
'Dim mbExit As Boolean

Private Sub TextBox1_Mouseup(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Static bExit As Boolean

Debug.Print "Button"; Button, "bExit "; bExit

If bExit Then
bExit = False
Debug.Print "Exit Sub"
Debug.Print
Exit Sub
End If

If Button = 2 Then
bExit = True
MouseClick
End If

End Sub

Sub MouseClick()
Debug.Print "MouseClick"

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
DoEvents
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

End Sub

But this prevents the default right-click to 'select entire word' ?

Regards,
Peter T
"RB Smissaert" wrote in message
...
Is there an easy way to set the cursor in a textbox in the the mouse down
event when the right mouse button is used?
This is an ordinary textbox in a VBA userform, so I am not sure the

Windows
API can help out here.

RBS