Solved

EXCEL VBA - RIGHT MOUSE CLICK MENU ACTIVATION

Posted on 2011-02-18
3
873 Views
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.
right-mouse-click-menu-activatio.jpg
0
Comment
Question by:FrankSasso
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
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.

jppinto
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

0
 
LVL 33

Assisted Solution

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

jppinto
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

0
 

Author Closing Comment

by:FrankSasso
ID: 34930030
thankyou
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

805 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