Hello,

I try to add a context menu to an excel sheet. The problem is that I
can not identify the current commandbar as it seems that this
commandbar is different wether you are in "normal view" or  - and that
is the problem here - you are in "page Break Preview". If the sheet is
in the normal view the following code works fine, but not if I am in
the "page Break Preview" Mode. I assume the commandbar will even
change if I have a comment in the cell or not and so on ... Is there a
way to identify the commandbar that will pop up after the
"BeforeRightClick"-Event?

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel
As Boolean)
 On Error Resume Next
        cmdid = Application.CommandBars("Cell").ID
'        cmdid = 427
        With Application
            .CommandBars(cmdid).Controls("Update Work Center in
SAP").Delete
            Set cBut
= .CommandBars(cmdid).Controls.Add(Temporary:=True)
        End With

        With cBut
           .Caption = "Update Work Center in SAP"
           .Style = msoButtonCaption
           .OnAction = "change_workcenter"
           .Parameter = Format(Target.value)
        End With
    On Error GoTo 0
End Sub

--~--~---------~--~----~------------~-------~--~----~
Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To post to this group, send email to excel-macros@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/excel-macros?hl=en

Visit & Join Our Orkut Community at 
http://www.orkut.com/Community.aspx?cmm=22913620

Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To Learn VBA Macros Please visit http://www.vbamacros.blogspot.com

To see the Daily Excel Tips, Go to:
http://exceldailytip.blogspot.com
-~----------~----~----~----~------~----~------~--~---

Reply via email to