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 November 20th, 2003, 06:47 PM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default CommandBarButton Click Event

I would appreciate if someone could help with this issue. I have four buttons in the CommandBar "CBAR". In the procedure below I am trying to link the first two buttons - "Calculate" and "Rebalance" to the following events - cmdCalculate and cmdRebalance. However, when I click on any of the four buttons from the CommandBar "CBAR" - each will trigger both events - cmdCalculate and cmdRebalance. Thank you, Ivan.

'Class1:

Option Explicit

Public WithEvents cmdCalculate As Office.CommandBarButton
Public WithEvents cmdRebalance As Office.CommandBarButton

Private Sub cmdCalculate_Click(ByVal cmdCalculate As CommandBarButton, CancelDefault As Boolean)
        MsgBox CommandBars("CBAR").Controls(1).Caption
End Sub

Private Sub cmdRebalance_Click(ByVal cmdRebalance As CommandBarButton, CancelDefault As Boolean)
        MsgBox CommandBars("CBAR").Controls(2).Caption
End Sub

'Module1:

Option Explicit
Private clsCBClass As New Class1

Sub InitEvents()
  Dim cmdCalculate As CommandBarButton
  Dim cmdRebalance As CommandBarButton
  Set clsCBClass.cmdCalculate = CommandBars("CBAR").Controls(1)
  Set clsCBClass.cmdRebalance = CommandBars("CBAR").Controls(2)
End Sub

'ThisWorkbook:

Private Sub Workbook_Open()
    InitEvents
End Sub
 
Old April 15th, 2008, 04:18 AM
Registered User
 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, I am having exactly the same problem. Did you find a solution?

 
Old April 16th, 2008, 02:52 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi Novelty

Try using the OnAction Property of commandbar controls

http://vbadud.blogspot.com/2007/05/a...-controls.html

http://vbadud.blogspot.com/2007/05/a...mmand-bar.html

Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Click event being cancelled!? Abbas ASP.NET 2.0 Professional 3 July 16th, 2007 05:18 PM
DataGrid click event Clive Astley Beginning VB 6 0 July 4th, 2005 12:44 AM
simulating click event simmohall BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 March 13th, 2005 06:28 PM
Click Event dkr72 C# 3 December 8th, 2004 06:23 PM





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