ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Control Sequence from Userform Control (https://www.excelbanter.com/excel-programming/319729-control-sequence-userform-control.html)

Nigel

Control Sequence from Userform Control
 
In a userform textbox I can use ctrl+v to paste a previously copied text
item. How can I intiate this sequence or indeed any other keyboard control
or escape sequence from a control button?
TIA

--
Cheers
Nigel





Nigel

Control Sequence from Userform Control
 
Hi All,
Discovered a method to paste as follows, however the event is triggered
twice so I paste the data twice, so my questions are

1. Why does the mousedown event run twice ?
2. If this is normal how do I handle this double event?

I need to be able to paste the contents of the clipboard into TextBox1 just
once, I could either apply extra code to prevent the double copying or clear
the clipboard after the first copy occurs - which is the better option and
how do I achieve this?

Private Sub TextBox1_MouseDown(ByVal Button As Integer _
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = 2 Then
SendKeys "^v"
End Sub

--
Cheers
Nigel



"Nigel" wrote in message
...
In a userform textbox I can use ctrl+v to paste a previously copied text
item. How can I intiate this sequence or indeed any other keyboard

control
or escape sequence from a control button?
TIA

--
Cheers
Nigel







Bob Phillips[_6_]

Control Sequence from Userform Control
 
Nigel,

Double events usually happen because the action within the event causes
exactly the same event that was initially trapped, firing the event a second
time before the first finishes. With worksheet and workbook events, you turn
EnableEvents off, but this doesn't work for forms, so you need to do it
yourself.

An example for you would be

Dim fReEntry As Boolean

Private Sub TextBox1_MouseDown(ByVal Button As Integer _
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Not fReEntry Then
fReEntry = True
If Button = 2 Then SendKeys "^v"
fReEntry = False
End If
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Hi All,
Discovered a method to paste as follows, however the event is triggered
twice so I paste the data twice, so my questions are

1. Why does the mousedown event run twice ?
2. If this is normal how do I handle this double event?

I need to be able to paste the contents of the clipboard into TextBox1

just
once, I could either apply extra code to prevent the double copying or

clear
the clipboard after the first copy occurs - which is the better option and
how do I achieve this?

Private Sub TextBox1_MouseDown(ByVal Button As Integer _
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = 2 Then
SendKeys "^v"
End Sub

--
Cheers
Nigel



"Nigel" wrote in message
...
In a userform textbox I can use ctrl+v to paste a previously copied text
item. How can I intiate this sequence or indeed any other keyboard

control
or escape sequence from a control button?
TIA

--
Cheers
Nigel









Nigel

Control Sequence from Userform Control
 
Hi Bob
Thanks for the reply. In fact I tried a similar approach to your proposal
but as with yours the setting of the boolean to False on exit allows the
retrigger to occur again! It appears that the whole event re-runs - if I
leave the boolean as false then I cannot reapply the paste until I unload
and reload the userform.

I could use another form event to set the boolean to False, but I just seem
to be building up layers of complexity that I do not feel happy about. It
has just got to be simpler than this - hasn't it??

---
Cheers
Nigel



"Bob Phillips" wrote in message
...
Nigel,

Double events usually happen because the action within the event causes
exactly the same event that was initially trapped, firing the event a

second
time before the first finishes. With worksheet and workbook events, you

turn
EnableEvents off, but this doesn't work for forms, so you need to do it
yourself.

An example for you would be

Dim fReEntry As Boolean

Private Sub TextBox1_MouseDown(ByVal Button As Integer _
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Not fReEntry Then
fReEntry = True
If Button = 2 Then SendKeys "^v"
fReEntry = False
End If
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Hi All,
Discovered a method to paste as follows, however the event is triggered
twice so I paste the data twice, so my questions are

1. Why does the mousedown event run twice ?
2. If this is normal how do I handle this double event?

I need to be able to paste the contents of the clipboard into TextBox1

just
once, I could either apply extra code to prevent the double copying or

clear
the clipboard after the first copy occurs - which is the better option

and
how do I achieve this?

Private Sub TextBox1_MouseDown(ByVal Button As Integer _
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If Button = 2 Then
SendKeys "^v"
End Sub

--
Cheers
Nigel



"Nigel" wrote in message
...
In a userform textbox I can use ctrl+v to paste a previously copied

text
item. How can I intiate this sequence or indeed any other keyboard

control
or escape sequence from a control button?
TIA

--
Cheers
Nigel












All times are GMT +1. The time now is 11:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com