Add Custom Macro Buttons to the Excel VBA Editor Toolbar
Question details
Add a command to the VBA Editor toolbar and automate repetitive code-editing tasks.

- Product
- Microsoft Excel Visual Basic Editor
- Device & OS
- not provided
- Scenario
- The user wants a toolbar command available while editing VBA code, including a way to insert text and find strings in a code module.
- Observed behavior
- A macro can be assigned to a worksheet button, but the user needs a command in the VBA Editor rather than on a worksheet.
Open the workbook in Excel and press Alt+F11 to open the Visual Basic Editor. Check whether a built-in toolbar command meets your needs before installing an add-in or enabling programmatic access to VBA projects.
Customize the VBA Editor toolbar or use an add-in
Use the editor's built-in customization for existing commands, or an add-in for a custom code-editing action.
A worksheet button runs a workbook macro but is not a button on the Visual Basic Editor toolbar. A custom editor command generally requires an add-in that creates a toolbar control and handles its click event.
In the Visual Basic Editor, choose View > Toolbars > Customize. On the Commands tab, browse the available commands.
Drag a command from the Customize dialog onto a visible editor toolbar, then close the dialog. Use the editor's Find command for manual searches if it meets your needs.
If no built-in command provides the required behavior, install or develop a trusted VBA Editor add-in that adds a CommandBar button and handles its click event. The handler can work with the active code pane and its code module.

Insert and find text in a VBA code module
Use this approach when a macro needs to make repeatable code changes rather than simulate keystrokes.
Work with Excel files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and Excel file compatibility for a smoother move between office suites. It does not customize or repair the Microsoft VBA Editor.

Frequently Asked Questions
Can I assign a worksheet macro button to the VBA Editor toolbar?
A worksheet control and a Visual Basic Editor toolbar control are separate. Use View > Toolbars > Customize in the editor for built-in commands, or use an add-in to implement a custom editor command.
How can I find a string in VBA code?
Open the module in the Visual Basic Editor and press Ctrl+F for a manual search. For a programmatic search, use the module's CodeModule.Find method with the required search range.
Why is my macro blocked from changing VBA code?
Excel may block programmatic project access. Check File > Options > Trust Center > Trust Center Settings > Macro Settings and the Trust access to the VBA project object model setting. A protected project or an organizational security policy may also restrict access.
Does the sample macro paste clipboard text at the cursor?
No. It uses the active code pane's selection to insert a fixed comment as a whole line. Pasting clipboard text at an exact cursor position requires additional clipboard, selection, and text-handling code.




