Run one Macro from clicking different Textbox Objects

S

SIR Knight

Hi,

I have a spreadsheet with a flowchart (created using Textboxes). I
have written some code that looks at the text content of the textbox
and performs actions based on the text. The question is:

How do I get the Macro to identify the textbox object I have clicked?
Eg. If I click on TextBox1 the macro recognises the content of
TextBox1, and if I click on TextBox2 recognise content of TextBox2 etc.

All help greatly appreciated

Thanks

Steve
 
B

Bernie Deitrick

Steve,

You should have a macro for each textbox, in which you call your main macro with a passed
parameter(s). For example, assign TB1 to Text Box 1, etc...

Sub TB1()
MainMacro ActiveSheet.TextBoxes("Text Box 1").Text
End Sub

Sub TB2()
MainMacro ActiveSheet.TextBoxes("Text Box 2").Text
End Sub

Sub MainMacro(myT As String)
MsgBox "Macro fired by textbox with the text """ & myT & """"
End Sub

HTH,
Bernie
MS Excel MVP
 

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