pass arguments to macros from a menu

R

Rudy

I use a menu in Word to activate a macro. I try to build each menu
voice that onaction call a macro with a different parameter values,
but it seems that it's not correct, the example is like:

Set myMenuBar = CommandBars.ActiveMenuBar
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlPopup, _
Temporary:=True)
newMenu.Caption = "ciao"
Set ctrl1 = newMenu.Controls _
.Add(Type:=msoControlButton, ID:=1, Before:=1 + i)
ctrl1.Caption = "ciao1"
ctrl1.Style = msoButtonCaption
ctrl1.OnAction = "'activatemacro 10'"
 
J

Jonathan West

Hi Rudy,

I'd approach this from a different direction.

Place the parameter you want to use into the tag property of the button or
menu item.

Then, in the macro, use the ActionControl property to find out which button
or menu item was used to trigger the macro. You can then read the Tag
property of the control and use it.
 
L

laurent.vanroy

I think one of the problemn is that you can't start a Sub from nothing
(ex. the Macro window) if this Sub takes parameters.

Why don't you develop specific small no-parameters macros for each of
your menu. Each of this macros will launch your main macro with the
desired data
 
T

Tushar Mehta

Jonathan's method is documented and a reliable way to go. An
alternative that has worked for many years but, to the best of my
knowledge, is undocumented is illustrated by Tom Ogilvy at
http://www.google.com/groups?threadm=MPG.1841959ae377513a98a860%
40msnews.microsoft.com

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2004
 

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