ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Get Active Object or Textbox Name to pass to sub (https://www.excelbanter.com/excel-programming/419750-get-active-object-textbox-name-pass-sub.html)

kenny

Get Active Object or Textbox Name to pass to sub
 
I have multiple text box - in the mouse down event for each - I want to pass
the name of the textboax to another module something like this

public controlname as control

sub mousedown()
controlname = activesheet.control.name

What is the correct code?

Also the mouse down event seems to happen twice upon one right click -
anyway to stop this - thanks so much for your help!


Peter T

Get Active Object or Textbox Name to pass to sub
 
Your mousedown event should look like this

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

End Sub

The name is typically "TextBox1". In some (untypical) scenarios the shape
name can be different to the OLEObject name, if you prefer that use
TextBox1.Name

Yes the mousedown event does run twice (I've discussed this before in this
ng). Are you sure GotFocus isn't a more appropriate event, otherwise
MouseUp. If you really need mousedown try something like this -

Static nEvnt As Long
If Button = 2 Then
nEvnt = nEvnt + 1
If nEvnt < 2 Then
Exit Sub
End If
End If
nEvnt = 0


Regards,
Peter T


"Kenny" wrote in message
...
I have multiple text box - in the mouse down event for each - I want to
pass
the name of the textboax to another module something like this

public controlname as control

sub mousedown()
controlname = activesheet.control.name

What is the correct code?

Also the mouse down event seems to happen twice upon one right click -
anyway to stop this - thanks so much for your help!




kenny

Get Active Object or Textbox Name to pass to sub
 
Peter thanks so much for your help. I wrote this mouse down (right click)
event that will fire another module and carry the objects name in a variable
with it. Im going to copy the same code to each of the mouse down events for
all textbox's on the sheet. The problem is I have to change "set popobject =
TextBox1" to the objects name in every mouse down event. Is there a way to
give the variable the object's name of which ever objects mousedown event I
am in. Such as "set popobject = Selected.Objects.Name" or something to that
effect.


"Peter T" wrote:

Your mousedown event should look like this

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

End Sub

The name is typically "TextBox1". In some (untypical) scenarios the shape
name can be different to the OLEObject name, if you prefer that use
TextBox1.Name

Yes the mousedown event does run twice (I've discussed this before in this
ng). Are you sure GotFocus isn't a more appropriate event, otherwise
MouseUp. If you really need mousedown try something like this -

Static nEvnt As Long
If Button = 2 Then
nEvnt = nEvnt + 1
If nEvnt < 2 Then
Exit Sub
End If
End If
nEvnt = 0


Regards,
Peter T


"Kenny" wrote in message
...
I have multiple text box - in the mouse down event for each - I want to
pass
the name of the textboax to another module something like this

public controlname as control

sub mousedown()
controlname = activesheet.control.name

What is the correct code?

Also the mouse down event seems to happen twice upon one right click -
anyway to stop this - thanks so much for your help!






All times are GMT +1. The time now is 08:53 AM.

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