Making Application.CommandBars.ExecuteMso method work in 2007

J

JeffreyW

In the Excel 2007 VBA Programmer's Reference (by John Green, Stephen Bullen,
Rob Bovey and Michael Alexander), they state:
-----
"As well as being able to retrieve the state information, you can also click
any built-in control using the new ComandBars.ExecuteMso method. This is
extremely useful for triggering those actions that don’t have an object model
equivalent—such as putting the user in drawing mode to draw a text box on a
sheet:"

Application.CommandBars.ExecuteMso “TextBoxInsertExcelâ€
-----

While the above works, when I try to use this method with a gallery control,
like:

Application.CommandBars.ExecuteMso "CellStylesGallery"

I expect either the book is wrong (i.e., the method does not apply to "any
built-in control"), or there is some syntax I have wrong in applying this.
Can anyone advise how to make this work?
 
N

Nick Hodge

Jeffery

Not quite got what you are seeing here, but to get the Mso of any control go
to Office Button>Excel Options>Customize and change the drop down to 'All
Commands', find the control in the list, hover over it until the tooltip
appears and the 'Mso' is the name in brackets e.g. (TextBoxInsertText), you
can then try using that in your VBA after the ExecuteMso statement.

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
web: www.nickhodge.co.uk
 
J

JeffreyW

Nick,

I do have the correct mso label in the following statement:

Application.CommandBars.ExecuteMso "CellStylesGallery"

Yet it fails with a "Run-time error '5': Invalid procedure call or argument".

I think the book is wrong - in fact, looking at Help more closely now, I see
that it says: "Works on controls that are built-in buttons, toggleButtons
and splitButtons."

So, by definition, I guess that excludes Gallery buttons.

Jeff
 
J

JeffreyW

Hi Ron,

Yeah, I think you are right. As indicated in my reply to Nick's post above,
Help indicates that the method only "Works on controls that are built-in
buttons, toggleButtons and splitButtons."

Jeff
 
J

JeffreyW

Ron, I was wondering if the method you suggested on another of my questions
recently:

Application.CommandBars.FindControl(ID:=23).Execute

.... might work here. I doubt it will given the failure of the .ExecuteMso
method but thought it was worth asking ... How do I find the "ID" for the
"CellStylesGallery" function to try this?

I tried looking at your "Built-in controls in Excel 2007.xlsm" file, but the
"Ordering" and "Policy ID" listed there did not work with the FindControl
method. Both generated errors:

"Run-time error '91':

Object variable or With block variable not set"

Jeff
 
R

Ron de Bruin

This is only working for the old 2003 controls Jeffrey.

No way to do what you want on this moment as far as I know
 

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