Get Active Object or Textbox Name to pass to sub

K

Kenny

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!
 
P

Peter T

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
 
K

Kenny

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.
 

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