Go Premium for a chance to win a PS4. Enter to Win



Posted on 2011-02-18
Medium Priority
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
  • 2
LVL 33

Accepted Solution

jppinto earned 2000 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 2000 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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

824 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