Can See CommandBarButton CommandBars("Cell")

theozz

Active Member
Joined
Jun 11, 2007
Messages
328
Many Tanks for Your Knowledge
this time I want know one question

Code:
at Application.CommandBars("Cell")

I add CommandBarButton but...

Code:
when ActiveWindow.View = xlNormalView
that time I can see New Added Button

but
Code:
ActiveWindow.View = xlPageBreakPreview
that time I can see New Added Button Never only Default button.

:eek: have any idea???:eek:
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi,
there are more than one "Cell" bar, as you should see here:

Code:
[COLOR="Navy"]Sub[/COLOR] f01()

[COLOR="Navy"]Dim[/COLOR] x [COLOR="Navy"]As[/COLOR] CommandBar
[COLOR="Navy"]Dim[/COLOR] intCount [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]

[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] x [COLOR="Navy"]In[/COLOR] Application.CommandBars
    [COLOR="Navy"]If[/COLOR] x.Name = "Cell" [COLOR="Navy"]Then[/COLOR]
        intCount = intCount + 1
        MsgBox "Command Bar Cell - " & intCount
    [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]Next[/COLOR] x

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]

Hence, you can resolve this by looping through all the Cell command bars and adding your button to both of them. In the following example I am adding a menu item, but you should be able to adapt the same approach with your button):

Code:
[COLOR="Navy"]Sub[/COLOR] f02()

[COLOR="Navy"]Dim[/COLOR] x [COLOR="Navy"]As[/COLOR] CommandBar
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] x [COLOR="Navy"]In[/COLOR] Application.CommandBars
    [COLOR="Navy"]If[/COLOR] x.Name = "Cell" [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]With[/COLOR] x.Controls
             [COLOR="Navy"]With[/COLOR] .Add
                .Caption = "New Command"
                .OnAction = ThisWorkbook.Name & "!MyMacro" 
                .Tag = "Formulas2" 
            [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
        [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
    [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]Next[/COLOR] x

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]

HTH,
ξ

Note:
For other readers of this post, helpful links on right click menus:
http://www.mvps.org/dmcritchie/excel/rightclick.htm
And XL2003 menus in general (not applicable to XL2007 or above):
http://support.microsoft.com/kb/830502
 
Last edited:
Upvote 0
Thanks guide

I cannot think :biggrin:

intCount = intCount + 1

by this method I found the Bars have 2 commandbarbutton sometimes...

Your advice is best answer for me thanks :eek:

have a good day today and more (__)(__)
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,967
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top