ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Execute a menu command with VBA? (https://www.excelbanter.com/excel-programming/296940-execute-menu-command-vba.html)

Susan[_3_]

Execute a menu command with VBA?
 
Is it possible to execute a menuitem from the standard Excel menu with VBA code?

I have tried this (and several variations) with no luck:
MenuBars(xlWorksheet).Menus("Data").MenuItems("For m...").Execute

I am trying to open the Data form in the above code but I would like to do other things to.

And, for general knowledge, is "Commandbars" interchangeable with "MenuBars"?

Thank you

Dick Kusleika[_2_]

Execute a menu command with VBA?
 
Susan

MenuBars probably still works, but it's the old way. It's not completely
interchangeable with Commandbars because toolbars are commandbars, but not
menubars. I think the problem with your code is that xlWorksheet isn't a
proper index of a menu. Try this

Sheet1.ShowDataForm

If you want to use the menu, it would look like this

CommandBars(1).Controls("Data").Controls("Form..." ).Execute

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

Susan wrote:
Is it possible to execute a menuitem from the standard Excel menu with
VBA code?

I have tried this (and several variations) with no luck:
MenuBars(xlWorksheet).Menus("Data").MenuItems("For m...").Execute

I am trying to open the Data form in the above code but I would like to
do other things to.

And, for general knowledge, is "Commandbars" interchangeable with
"MenuBars"?

Thank you




Susan[_3_]

Execute a menu command with VBA?
 
Dick Kusleika wrote:
Susan

MenuBars probably still works, but it's the old way. It's not completely
interchangeable with Commandbars because toolbars are commandbars, but not
menubars. I think the problem with your code is that xlWorksheet isn't a
proper index of a menu. Try this

Sheet1.ShowDataForm

If you want to use the menu, it would look like this

CommandBars(1).Controls("Data").Controls("Form..." ).Execute

Thanks, Dick


All times are GMT +1. The time now is 04:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com