Solved

EXCEL VBA - RIGHT MOUSE CLICK MENU ACTIVATION

Posted on 2011-02-18
3
877 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:Frank .S
[X]
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
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:Frank .S
ID: 34930030
thankyou
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

739 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