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 (892 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 Skilled (749 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 Skilled (749 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 Skilled (749 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
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.


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