PDA

View Full Version : Word VBA equivalent of Application.Caller



SOS
06-11-2008, 12:49 AM
Hi all,

I'm working with a document and want to be able to capture the name of the CheckBox which started the routine. I know that in Excel VBA the code:



Application.Caller


will return the name of the object clicked but is there an equivalent code line in Word VBA.

As always help is much appreciated.

Seamus

fumei
06-11-2008, 10:02 AM
ActiveControl

I am not quite following what you are saying, but...

Sub CheckBox1_Change()
Dim ctl As Control
Set ctl = Me.ActiveControl
MsgBox ctl.Name
End Sub

would display the name ("Checkbox1") when the control was changed.

As you do not actually state clearly, I have no idea if this checkbox is on a userform, or not. The code above is for a checkbox on a userform.

Please clarify.

Here is a demo that may help. The userform displays on document open. There are two checkboxes, and two textboxes. Plus a Label - to display a message, and a commandbutton which just unloads the userform.

I have it so that on Exit the checkboxes and the textboxes will show their Name in the Label, as the last active control.

As you did not make yourself very clear, I hope this will at least help give you an idea of how to resolve your question.

If you need the last control Name for some other purpose, I would make it a Public string variable.

SOS
06-11-2008, 02:36 PM
Sorry fumei,

Will try in future to be clearer in my requests for help. I have since worked another way around the difficulty but many thanks for your input as always.

Regards

Seamus

fumei
06-12-2008, 10:04 AM
"I have since worked another way around the difficulty"

Then by all means please tell us what that is. Maybe it will helps others, or me! If you have a better way, share!