Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2007, 08:03 PM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Before Right Click showpopup menu

I've been trying to get the code below to produce a menu on right click from a spreadsheet but it always ends in an error on the line

CommandBars("Data Popup").ShowPopup


but I can't work out why.

Do the two routines need to be in specific places for it to work? What am I missing?

Thanks
Dave


Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)


   If Not Intersect(Range("database"), Target) Is Nothing Then

     CommandBars("Data Popup").ShowPopup
      Cancel = True
   End If

End Sub




Sub MakePopup()
'Get rid of any existing toolbar called Data Popup
    On Error Resume Next
    CommandBars("Data Popup").Delete
    On Error GoTo 0

    'Add new popup commandbar
    With CommandBars.Add(Name:="Data Popup", Position:=msopopup)


        'Add controls
        With .Controls.Add(Type:=msoControlButton)
            .OnAction = "ShowDataForm"
            .FaceId = 264
            .Caption = "Data Form"
            .TooltipText = "Show Data Form"
        End With

        With .Controls.Add(Type:=msoControlButton)
            .Caption = "Sort Ascending"
            .FaceId = 210
            .OnAction = "SortList"
            .Parameter = "Asc"
        End With

        With .Controls.Add(Type:=msoControlButton)
            .Caption = "Sort Decending"
            .FaceId = 211
            .OnAction = "SortList"
            .Parameter = "Dsc"
        End With

    End With

End Sub







Similar Threads
Thread Thread Starter Forum Replies Last Post
Right click to Open a menu peace2007 Ajax 2 November 5th, 2007 02:25 AM
right click on a menu item chuckcottle C++ Programming 3 May 14th, 2007 10:34 AM
right click menu hidden by drop-drown menu Andraw HTML Code Clinic 0 March 18th, 2005 03:28 PM
ShowPopup doen't fire events on menu bar sumit_kalra Access VBA 1 March 3rd, 2005 11:13 AM
ShowPopup doesn't fire events on menu bar sumit_kalra Excel VBA 0 July 12th, 2003 06:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.