Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Objects assigned to same macro

Status
Not open for further replies.

BoFenger

Programmer
Aug 6, 2003
22
DK
Hi
I'am working in excel VBA
If I assign two different object (fx. a textbox) to the same macro, how do the macro know which object the macro is assigned from.

\Bo
 
Hi Bo,

AFAIK, you can't assign two objects to the same macro. Could you be a bit more specific please.

Enjoy,
Tony
 
Hi
I have 50 textboxes in an excel sheet that has to write a test next to the textbox. Instead of making 50 macroes, I would like to make one macro, that knows which of the textboxes I have pressed and therebye write the text the right place. Hope I have been a bit more specific

\Bo
 
Hi BoFenger,

Sorry, don't believe it can be done. You can't tell Excel which macro to run. Also I don't know what you mean by pressing a textbox; you press a button.

You could have 50 simple macros (on a double click perhaps)which all called a common routine, something like this ..

Code:
Sub TextBox1_DblClick(Cancel as boolean)
    Call CommonCode(Me.TextBox1)
End Sub
Sub TextBox2_DblClick(Cancel as boolean)
    Call CommonCode(Me.TextBox2)
End Sub
:
:
etc.
:
:
Code:
Sub CommonCode(myBox)
:
Code:
' Your code here
Code:
:
End Sub

I'd really need more details to help further.

Enjoy,
Tony
 
Bo,

Did you read my other post to this similar question?

Using Tony's suggestion...
Code:
Sub TextBox1_DblClick(Cancel as boolean)
    Call CommonCode(Me.TextBox1) Textbox1.TopLeftCell
End Sub
Sub TextBox2_DblClick(Cancel as boolean)
    Call CommonCode(Me.TextBox2) Textbox2.TopLeftCell
End Sub
Then in the CommonCode routine...
Code:
sub CommonCode(rng As Range)
   select case rng.address
     case "A1"
        'process for the textbox in A1
...
     case "A3"
        'process for the textbox in A3
...
   end select
end sub
?? It's another way related to your original question.

Skip,
Skip@TheOfficeExperts.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top