+ Reply to Thread
Results 1 to 4 of 4

Call Macro using right click menu

  1. #1
    Ivan
    Guest

    Call Macro using right click menu

    Dear all,

    I want to write a macro program so that when right click at on the
    worksheet, an item is added to the right-click menu with the name of macro
    function, so that the users can call the macro program by right clicking the
    worksheet. On the other hand, other regular items such as "Copy",
    "Paste",..,etc., should be preserved on the right-click menu.
    Can anyone advise how to do this programatically? Thanks in advance!

    Ivan

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Right Click Menu

    Why not just add a command button with the macro assigned
    ----------------
    Ben

  3. #3
    Dave Peterson
    Guest

    Re: Call Macro using right click menu

    One way:

    Option Explicit
    Sub auto_close()
    Call CleanUpPly
    End Sub
    Sub auto_open()

    Dim iCtr As Long
    Dim myMacros As Variant
    Dim myCaptions As Variant

    Call CleanUpPly

    Dim cb As CommandBar
    Set cb = Application.CommandBars("ply")

    myMacros = Array("mac1", "mac2", "mac3")
    myCaptions = Array("Cap 1", "Cap 2", "Cap 3")

    With cb.Controls
    For iCtr = LBound(myMacros) To UBound(myMacros)
    With .Add(Type:=msoControlButton, temporary:=True)
    .Caption = myCaptions(iCtr)
    .OnAction = "'" & ThisWorkbook.Name & "'!" & myMacros(iCtr)
    .Tag = "__myPlyMacs__"
    End With
    Next iCtr
    End With

    End Sub
    Sub CleanUpPly()
    Dim ctrl As CommandBarControl

    On Error Resume Next
    Do
    Set ctrl = Application.CommandBars("Ply") _
    .FindControl(Tag:="__myPlyMacs__")
    If ctrl Is Nothing Then
    Err.Clear
    Exit Do
    End If
    ctrl.Delete
    Loop
    On Error GoTo 0

    End Sub

    Ivan wrote:
    >
    > Dear all,
    >
    > I want to write a macro program so that when right click at on the
    > worksheet, an item is added to the right-click menu with the name of macro
    > function, so that the users can call the macro program by right clicking the
    > worksheet. On the other hand, other regular items such as "Copy",
    > "Paste",..,etc., should be preserved on the right-click menu.
    > Can anyone advise how to do this programatically? Thanks in advance!
    >
    > Ivan


    --

    Dave Peterson

  4. #4
    Ivan
    Guest

    Re: Call Macro using right click menu

    Thanks a lot Dave!

    "Dave Peterson" wrote:

    > One way:
    >
    > Option Explicit
    > Sub auto_close()
    > Call CleanUpPly
    > End Sub
    > Sub auto_open()
    >
    > Dim iCtr As Long
    > Dim myMacros As Variant
    > Dim myCaptions As Variant
    >
    > Call CleanUpPly
    >
    > Dim cb As CommandBar
    > Set cb = Application.CommandBars("ply")
    >
    > myMacros = Array("mac1", "mac2", "mac3")
    > myCaptions = Array("Cap 1", "Cap 2", "Cap 3")
    >
    > With cb.Controls
    > For iCtr = LBound(myMacros) To UBound(myMacros)
    > With .Add(Type:=msoControlButton, temporary:=True)
    > .Caption = myCaptions(iCtr)
    > .OnAction = "'" & ThisWorkbook.Name & "'!" & myMacros(iCtr)
    > .Tag = "__myPlyMacs__"
    > End With
    > Next iCtr
    > End With
    >
    > End Sub
    > Sub CleanUpPly()
    > Dim ctrl As CommandBarControl
    >
    > On Error Resume Next
    > Do
    > Set ctrl = Application.CommandBars("Ply") _
    > .FindControl(Tag:="__myPlyMacs__")
    > If ctrl Is Nothing Then
    > Err.Clear
    > Exit Do
    > End If
    > ctrl.Delete
    > Loop
    > On Error GoTo 0
    >
    > End Sub
    >
    > Ivan wrote:
    > >
    > > Dear all,
    > >
    > > I want to write a macro program so that when right click at on the
    > > worksheet, an item is added to the right-click menu with the name of macro
    > > function, so that the users can call the macro program by right clicking the
    > > worksheet. On the other hand, other regular items such as "Copy",
    > > "Paste",..,etc., should be preserved on the right-click menu.
    > > Can anyone advise how to do this programatically? Thanks in advance!
    > >
    > > Ivan

    >
    > --
    >
    > Dave Peterson
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1