PC Review


Reply
Thread Tools Rate Thread

Determining what menu item called a macro

 
 
Stephen Lloyd
Guest
Posts: n/a
 
      5th Aug 2008
I'm creating an xla that will add a custom menu that will be added to the
main menu bar. My hope is to have several of the menu items actually tied to
the same macro which will run (portions of the) code conditionally based on
the calling menu item.

Is there a property to determine what menu item called a routine? If so,
what is it and are there any limitations I should be aware of? Any
additional information would be awesome...i.e., obect/collection information,
etc.

I didn't find much in Excel's help files.
 
Reply With Quote
 
 
 
 
Wigi
Guest
Posts: n/a
 
      5th Aug 2008
Hi

You can use the OnAction methode of a menu item, AND pass some parameters
along to a general procedure. I know it can be done since in the past I
already coded something in that spirit.

I just googled:

excel vba onaction parameter

and have a look at these links, and start with the article from MVP Tushar
Mehta.


--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"Stephen Lloyd" wrote:

> I'm creating an xla that will add a custom menu that will be added to the
> main menu bar. My hope is to have several of the menu items actually tied to
> the same macro which will run (portions of the) code conditionally based on
> the calling menu item.
>
> Is there a property to determine what menu item called a routine? If so,
> what is it and are there any limitations I should be aware of? Any
> additional information would be awesome...i.e., obect/collection information,
> etc.
>
> I didn't find much in Excel's help files.

 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      5th Aug 2008
Take a look at application.caller
--
HTH...

Jim Thomlinson


"Stephen Lloyd" wrote:

> I'm creating an xla that will add a custom menu that will be added to the
> main menu bar. My hope is to have several of the menu items actually tied to
> the same macro which will run (portions of the) code conditionally based on
> the calling menu item.
>
> Is there a property to determine what menu item called a routine? If so,
> what is it and are there any limitations I should be aware of? Any
> additional information would be awesome...i.e., obect/collection information,
> etc.
>
> I didn't find much in Excel's help files.

 
Reply With Quote
 
Stephen Lloyd
Guest
Posts: n/a
 
      5th Aug 2008
Thank you both for your responses.

Jim, I had looked at application.caller and thought that it would not return
useful information if vba was called from a menu. I will look at it again
though.

Wigi, thank you for your help as well. I've looked at Mehta's stuff before
and found him helpful.

"Jim Thomlinson" wrote:

> Take a look at application.caller
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Stephen Lloyd" wrote:
>
> > I'm creating an xla that will add a custom menu that will be added to the
> > main menu bar. My hope is to have several of the menu items actually tied to
> > the same macro which will run (portions of the) code conditionally based on
> > the calling menu item.
> >
> > Is there a property to determine what menu item called a routine? If so,
> > what is it and are there any limitations I should be aware of? Any
> > additional information would be awesome...i.e., obect/collection information,
> > etc.
> >
> > I didn't find much in Excel's help files.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Aug 2008
I think you want actioncontrol, as in:

msgbox Application.CommandBars.ActionControl.Caption





Stephen Lloyd wrote:
>
> I'm creating an xla that will add a custom menu that will be added to the
> main menu bar. My hope is to have several of the menu items actually tied to
> the same macro which will run (portions of the) code conditionally based on
> the calling menu item.
>
> Is there a property to determine what menu item called a routine? If so,
> what is it and are there any limitations I should be aware of? Any
> additional information would be awesome...i.e., obect/collection information,
> etc.
>
> I didn't find much in Excel's help files.


--

Dave Peterson
 
Reply With Quote
 
Stephen Lloyd
Guest
Posts: n/a
 
      6th Aug 2008
and Dave Peterson comes through on the river. Thank you sir. One follow up
question. Is there any reason for which one should prefer to use any one of
the FaceId, Tag, or Caption properties in lieu of the other two?


"Dave Peterson" wrote:

> I think you want actioncontrol, as in:
>
> msgbox Application.CommandBars.ActionControl.Caption
>
>
>
>
>
> Stephen Lloyd wrote:
> >
> > I'm creating an xla that will add a custom menu that will be added to the
> > main menu bar. My hope is to have several of the menu items actually tied to
> > the same macro which will run (portions of the) code conditionally based on
> > the calling menu item.
> >
> > Is there a property to determine what menu item called a routine? If so,
> > what is it and are there any limitations I should be aware of? Any
> > additional information would be awesome...i.e., obect/collection information,
> > etc.
> >
> > I didn't find much in Excel's help files.

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      6th Aug 2008
The .tag property is something you can use that is invisible to the user.

I'd use the .tag property.

And if, er, when, you get complaints from the user to change the caption, you
can fix one thing without having to worry about what else you broke.

And if you have lots of controls that do the same kind of thing, you could add
the same tag to each.

(I can't imagine having to remember the cryptic FaceID's <vbg>.)

Stephen Lloyd wrote:
>
> and Dave Peterson comes through on the river. Thank you sir. One follow up
> question. Is there any reason for which one should prefer to use any one of
> the FaceId, Tag, or Caption properties in lieu of the other two?
>
> "Dave Peterson" wrote:
>
> > I think you want actioncontrol, as in:
> >
> > msgbox Application.CommandBars.ActionControl.Caption
> >
> >
> >
> >
> >
> > Stephen Lloyd wrote:
> > >
> > > I'm creating an xla that will add a custom menu that will be added to the
> > > main menu bar. My hope is to have several of the menu items actually tied to
> > > the same macro which will run (portions of the) code conditionally based on
> > > the calling menu item.
> > >
> > > Is there a property to determine what menu item called a routine? If so,
> > > what is it and are there any limitations I should be aware of? Any
> > > additional information would be awesome...i.e., obect/collection information,
> > > etc.
> > >
> > > I didn't find much in Excel's help files.

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining which Menu Item is Clicked Elliot Microsoft VB .NET 1 10th Mar 2005 10:19 PM
New menu item OnAction can't see macro? Ed Microsoft Excel Programming 13 25th Jan 2005 11:27 PM
Q: no Macro-> security menu item =?Utf-8?B?SklNLkgu?= Microsoft Access 3 14th Jan 2005 10:54 PM
Which macro behind menu item? =?Utf-8?B?SmFtZXM=?= Microsoft Access VBA Modules 2 9th Sep 2004 04:32 PM
Macro to display a menu item - possible? TonyJeffs Microsoft Excel Programming 3 16th Nov 2003 08:38 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:55 AM.