Posted on 2011-02-18
Last Modified: 2012-05-11
hi i would like all the code for EXCEL VBA (office 2003) - Windows 2003 to create a right mouse click menu activation event to add to my automated excel spreadsheet. I want to add this so that i can add selections to this menu that will activate other functions.
I have posted a sample right mouse menu click screenshot for your reference.
Question by:Frank .S
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 33

Accepted Solution

jppinto earned 500 total points
ID: 34929835
Excel already has a right mouse click menu on the worksheet. What you can do is add options to that menu.
Here's a sample code to add 3 more options that will open 3 userforms.

Sub AlterWorkSheetPopup2()
    Dim oCtrl As Object
    Dim arr1 As Variant, arr2 As Variant
    arr1 = Array("Click Here", "Click Now", "Click Next") 'Button names
    arr2 = Array("UsrfrmShow", "UsrfrmShow", "UsrfrmShow") 'Macro Names
    With Application.CommandBars("Cell")
        'Add a new menu
        For i = 0 To UBound(arr1)
            With .Controls.Add(msoControlButton)
                .Caption = arr1(i)
                .OnAction = arr2(i)
            End With
        Next i
    End With
End Sub

Open in new window

LVL 33

Assisted Solution

jppinto earned 500 total points
ID: 34929847
This sample code add options to the right click menu that will fire macros.

Sub AddItemsToRightClickMenu()
Dim myBar As Object, newItem As Object

Set newItem = CommandBars("Cell").Controls.Add(Type:=msoControlButton)
With newItem
    .BeginGroup = True
    .Caption = "My Macro Button 1"
    .FaceId = 49
    .OnAction = "PERSONAL.XLS!MyMacro1"
End With

Set newItem = CommandBars("Cell").Controls.Add(Type:=msoControlButton)
With newItem
    .Caption = "My Macro Button 2"
    .FaceId = 50
    .OnAction = "PERSONAL.XLS!MyMacro2"
End With

' Add more items here...

End Sub

Open in new window


Author Closing Comment

by:Frank .S
ID: 34930030

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question