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 February 18th, 2009, 04:29 AM
Authorized User
 
Join Date: Mar 2008
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default Problem with CommandBar's msoControlPopup control

I am trying to add my own popup menu into CommandBars("Cell").
The name of menu is successfully created, but I can't add buttons into that menu. AutoComplete shows no Add method. How to solve this problem?

Code:
Sub AddShortCut()
    
    Dim cb As CommandBar
    Dim ct As CommandBarControl
    Dim index As Integer
    
    Set cb = CommandBars("Cell")
    index = cb.Controls("Cut").index
    
    Set ct = cb.Controls.Add(Type:=msoControlPopup, Before:=index)
    ct.Caption = "Bonus"
    
    Call ClearRefs(cb, ct)
    
End Sub


Private Sub ClearRefs(ParamArray refs() As Variant)
    Dim ref As Variant
    For Each ref In refs
        Set ref = Nothing
    Next
End Sub
 
Old February 18th, 2009, 04:47 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Here is a hint

Code:
Sub AddShortCut_V1()
    
    Dim cb As CommandBar
    Dim ct As CommandBarControl
    Dim index As Integer
    Dim cb1 As CommandBarButton
    
    Set cb = CommandBars("Cell")
    index = cb.Controls("Cut").index
    
    
    
    Set ct = cb.Controls.Add(Type:=msoControlPopup, Before:=index)
    ct.Caption = "Bonus"
    
    Set cb1 = ct.Controls.Add(Type:=msoControlButton)
    cb1.Caption = "New Button"
    
    Call ClearRefs(cb, ct)
    
End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
The Following User Says Thank You to Shasur For This Useful Post:
sektor (February 18th, 2009)
 
Old February 18th, 2009, 05:07 AM
Authorized User
 
Join Date: Mar 2008
Posts: 74
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via ICQ to sektor
Default Thanks a lot!

Shasur, thanks a lot!!!!! But I wonder, why the Controls property isn't shown in AutoComplete? And the same thing happens to Cell's properties.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem while using User Control vivekshah ASP.NET 1.0 and 1.1 Professional 0 August 7th, 2008 02:46 AM
Monthview Control Problem krupalb Pro VB 6 0 September 4th, 2007 05:18 AM
Much much problem with the User Control! daffodils ASP.NET 1.0 and 1.1 Basics 7 October 20th, 2006 10:46 AM





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