How to Create an Excel VBA Menu: DoCmd.AddMenu Alternative
Question details
The user is trying to initialize a custom menu object in Excel VBA using the DoCmd.AddMenu method but needs a working alternative because this specific method is not natively supported in Excel.
- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Creating an interactive custom menu for an Excel macro project to improve user navigation.
- Observed behavior
- The VBA code fails to execute because DoCmd.AddMenu is specific to Microsoft Access, prompting the need for the correct way to instantiate and show a menu in Excel VBA.
Ensure the Developer tab is enabled in your Excel ribbon so you can access the Visual Basic for Applications (VBA) editor.
Create a Custom Menu Using an Excel VBA UserForm
Since DoCmd.AddMenu is exclusively a Microsoft Access method, the standard approach in Excel VBA is to design a UserForm that acts as your custom menu.
The DoCmd object is part of the Microsoft Access object model and is used to execute macro actions in Access forms and reports. Excel VBA does not recognize this object.
To achieve the exact same functionality in Excel, you must create a custom dialog box (UserForm), populate it with navigation controls like a ListBox or CommandButtons, and then initialize it through a standard module.
Press Alt + F11 on your keyboard to open the Visual Basic Editor in Excel.
In the top menu, click 'Insert' and select 'UserForm'. In the Properties window (F4), change the name of the form to 'frmMenu'.
From the Toolbox, drag and drop a ListBox onto your UserForm. This will hold your menu options.
Insert a new standard Module (Insert > Module) and write the following code to initialize and display your menu: `Dim Menu As frmMenu` `Set Menu = New frmMenu` `Menu.Show`
Create and Run Macros Seamlessly in WPS Office
WPS Office provides excellent support for VBA macros and UserForms, allowing you to automate tasks and build custom interactive menus exactly as you would in Microsoft Excel.
- 1. Access the Developer Tools: Open WPS Spreadsheet and navigate to the Developer tab on the ribbon.
- 2. Open the VBA Editor: Click on the Visual Basic Editor (VBE) icon to open the coding environment.
- 3. Design Your Menu: Click Insert > UserForm and use the toolbox to design your custom menu interface with list boxes or buttons.
- 4. Run the Macro: Write your initialization script and click the Run button or assign the macro to a shape in your worksheet.

Frequently Asked Questions
Why do I get a runtime error when using DoCmd in Excel VBA?
The DoCmd object is strictly part of the Microsoft Access object model. Excel VBA uses different core objects (like Application, Workbook, and Worksheet), so calling DoCmd in Excel will trigger an 'Object Required' or 'Variable Not Defined' error.
How do I populate a ListBox in my VBA UserForm menu?
You can populate a ListBox dynamically by double-clicking the UserForm to open its code window, selecting the 'Initialize' event, and using the `ListBox1.AddItem "Menu Option 1"` method for each item you want to display.
Can I create a custom menu in Excel without using VBA?
Yes, for simple drop-down menus within cells, you can use Excel's Data Validation feature (Data > Data Validation > Allow: List) without needing to write any VBA code.




