PDA

View Full Version : Solved: Variables



Levski
05-02-2005, 03:18 PM
I have inserted a new menu on the toolbar within which I will have several items of the same macro:

Sub Macro1()
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DOCVARIABLE ""Name""", PreserveFormatting:=True
End Sub

What I would like to do is replace 'Name' with whatever references the label of the item that has been clicked.

Can this be done?

Killian
05-02-2005, 03:43 PM
If I understand correctly you want the feild to had a document varicle field that has the mane of the control you clicked?
If thats the case, then you can refer to the ActionControl (the control that fired the macro and use it's properties or methods.
Here, I've tweaked your code a little and the varible name is taken from the actioncontrol's captionSub Macro1()
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldDocVariable, Text:= _
Application.CommandBars.ActionControl.Caption, PreserveFormatting:=True
End Sub

Levski
05-02-2005, 03:54 PM
Thanks perfect. Thank you :yes