0 votes
in VBA by Beginner (9 points)

How can i add some button or menu or gallery here ?

This `XML` code not working! Please help! (If i add the `s` letter at the end it's also not working!)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
		<contextMenu idMso="ContextMenuShape">
			<button idMso="About"/>


by Expert (916 points)
Can you post more details about the problem?
by Beginner (9 points)

Yes. Look Screencast.

I find this tutorial. It's work but i need to add some `Gallery` to "Context Menu". With `VBA` don't know how to realize it, with `XML` i know but it's not worling that is the problem!


1 Answer

+1 vote
by Expert (911 points)
selected by
Best answer

Follow Ron de Bruin's excellent instructions in the tutorial you referenced. Simply rename his 
Sub AddToCellMenu() and make it Sub AddToShapesMenu() then rename his 
Sub DeleteFromCellMenu() and make it Sub DeleteFromShapesMenu() then change the first few lines of each as follows:

Sub AddToShapesMenu()
    Dim ContextMenu As CommandBar
    Dim MySubMenu As CommandBarControl

    'Delete the controls first to avoid duplicates
    Call DeleteFromShapesMenu

    'Set ContextMenu to the Shapes menu
    Set ContextMenu = Application.CommandBars("Shapes")


Sub DeleteFromShapesMenu()
    Dim ContextMenu As CommandBar
    Dim ctrl As CommandBarControl

    'Set ContextMenu to the Shapes menu
    Set ContextMenu = Application.CommandBars("Shapes")


Private Sub Workbook_Activate()
    Call AddToShapesMenu
End Sub

Private Sub Workbook_Deactivate()
    Call DeleteFromShapesMenu
End Sub

Here is the result:


by Beginner (9 points)


Heh, brother I know this trick. I did not understand why nothing is added through `XML` (there are many possibilities).

by Expert (911 points)

I think I understand now. Ryan previously provided a tutorial on How to Make Custom Ribbons using XML and VBA. What you want is a similar tutorial on custom context menus using XML and VBA. Maybe Ryan is listening.

by Beginner (9 points)

 I've read this article and similar ones on other websites. That's not what I want! The problem lies in the name "Context Menu" for `Notes`.

by Expert (911 points)
edited by

Notes used to be called Comments. Some twisted soul at Microsoft changed the meaning of Comments, which are now threaded, dated, and have a Reply box. As illustrated in my previous Answer, the Context Menu for Notes is named Shapes:

Set ContextMenu = Application.CommandBars("Shapes")

Also, Ron de Bruin has already provided a tutorial for custom context menus using XML and VBA.

by Beginner (9 points)

0Key I find that it's not possible to add `menu` or `gallery` to "ContextMenuShapes":


 Only five of these command bar controls can be added to your custom toolbars and menus.
msoControlType.msoControlButton - Buttons with or without images
msoControlType.msoControlEdit - Textbox allows you to enter text
msoControlType.msoControlDropDown - Only allows you to select from the list.
msoControlType.msoControlComboBox - Lets you enter a value as well as being able to select from the list.
msoControlType.msoControlPopup - Used for menus and submenus.

XML + VBA works fine for "ContextMenuCell" and we can add `menu` or `gallery`.

Welcome to wellsr Q&A
Ask any questions you have about VBA and Python and our community will help answer them. wellsr Q&A is the standalone question and answer platform for wellsr.com. If you have a question about one of our specific tutorials, please include a link back to the tutorial.

Getting Started
VBA Cheat Sheets (On Sale Now)

Looking for something else? Hire our team directly through ourVBA Help page, instead.

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.