PC Review


Reply
Thread Tools Rate Thread

Adding AUTOSUM to Cell menu in Excel 2007

 
 
WhytheQ
Guest
Posts: n/a
 
      12th Feb 2008
In 2003 I could do the following:

Application.CommandBars("Cell").Controls.Add
msoControlSplitButtonPopup, 226

........and an Autosum control would be created in the Cell menu.

(I found 226 by recording a macro of changing a menu)

In 2007 the above line doesn't seem to work. Although it doesn't throw
an error either! ...

Any help greatly appreciated

Regards
JasonQ
 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      12th Feb 2008
Very interesting. It appears that what we see after right-clicking a cell
is not the "cell" commandbar. At least it is not the "cell" commandbar we
can modified with code.

After running your code run this:

commandbars("cell").ShowPopup

You should see AutoSum at the bottom. But notice that this commandbar has
black font, not blue. And that it doesn't have the floatie thing on top.

--
Jim
"WhytheQ" <(E-Mail Removed)> wrote in message
news:50bb05d8-27fd-48b8-af0e-(E-Mail Removed)...
| In 2003 I could do the following:
|
| Application.CommandBars("Cell").Controls.Add
| msoControlSplitButtonPopup, 226
|
| .......and an Autosum control would be created in the Cell menu.
|
| (I found 226 by recording a macro of changing a menu)
|
| In 2007 the above line doesn't seem to work. Although it doesn't throw
| an error either! ...
|
| Any help greatly appreciated
|
| Regards
| JasonQ


 
Reply With Quote
 
ilia
Guest
Posts: n/a
 
      12th Feb 2008
Yes, however I'm running this code from J-Walk's Power Programming:

Sub AddToShortCut()
' Adds a menu item to the Cell shortcut menu
Dim Bar As CommandBar
Dim NewControl As CommandBarButton
DeleteFromShortcut
Set Bar = CommandBars("Cell")
Set NewControl = Bar.Controls.Add _
(Type:=msoControlButton, ID:=1, _
temporary:=True)
With NewControl
.Caption = "Toggle &Word Wrap"
.OnAction = "ToggleWordWrap"
.Picture = Application.CommandBars.GetImageMso("WrapText", 16,
16)
.Style = msoButtonIconAndCaption
End With
End Sub

And it works. Also, I'm trying the following code:

Public Sub commandBarsTest()
Dim cbar As Office.CommandBar
Dim ctrl As Office.CommandBarControl

Set cbar = CommandBars("Cell")

For Each ctrl In cbar.Controls
Debug.Print ctrl.ID, ctrl.Caption, _
ctrl.Visible, ctrl.Enabled
Next ctrl
End Sub

Both the "Toggle Word Wrap" and AutoSum are listed (after running OP's
code to include it), but when using the popup in cell only the Toggle
Word Wrap is there - not the AutoSum.

It might have something to do with Control's ID property? This code
works, meaning I see "Test" in the in-cell shortcut menu:

Public Sub testControls()
Dim cbar As Office.CommandBar
Dim ctrl As Office.CommandBarControl

Set cbar = CommandBars("Cell")

Set ctrl = cbar.Controls.Add(ID:=1)

ctrl.Visible = True
ctrl.Enabled = True
ctrl.Caption = "Test"
End Sub

On Feb 12, 11:06 am, "Jim Rech" <jrr...@live.com> wrote:
> Very interesting. It appears that what we see after right-clicking a cell
> is not the "cell" commandbar. At least it is not the "cell" commandbar we
> can modified with code.
>
> After running your code run this:
>
> commandbars("cell").ShowPopup
>
> You should see AutoSum at the bottom. But notice that this commandbar has
> black font, not blue. And that it doesn't have the floatie thing on top.
>
> --
> Jim"WhytheQ" <Whyt...@gmail.com> wrote in message
>
> news:50bb05d8-27fd-48b8-af0e-(E-Mail Removed)...
> | In 2003 I could do the following:
> |
> | Application.CommandBars("Cell").Controls.Add
> | msoControlSplitButtonPopup, 226
> |
> | .......and an Autosum control would be created in the Cell menu.
> |
> | (I found 226 by recording a macro of changing a menu)
> |
> | In 2007 the above line doesn't seem to work. Although it doesn't throw
> | an error either! ...
> |
> | Any help greatly appreciated
> |
> | Regards
> | JasonQ


 
Reply With Quote
 
Jim Rech
Guest
Posts: n/a
 
      12th Feb 2008
>>It might have something to do with Control's ID property?

I'd guess it's the Type property. The autosum is of type
msoControlSplitButtonPopup and that is not listed among the types the
commandbar controls Add method supports per Help. Nevertheless Excel 2003
did support it and Excel 2007 does only on the 'shadow' cell menu. Go
figure.

Thanks for the additional information.

--
Jim
"ilia" <(E-Mail Removed)> wrote in message
news:e826dedc-104c-4380-a6ec-(E-Mail Removed)...
| Yes, however I'm running this code from J-Walk's Power Programming:
|
| Sub AddToShortCut()
| ' Adds a menu item to the Cell shortcut menu
| Dim Bar As CommandBar
| Dim NewControl As CommandBarButton
| DeleteFromShortcut
| Set Bar = CommandBars("Cell")
| Set NewControl = Bar.Controls.Add _
| (Type:=msoControlButton, ID:=1, _
| temporary:=True)
| With NewControl
| .Caption = "Toggle &Word Wrap"
| .OnAction = "ToggleWordWrap"
| .Picture = Application.CommandBars.GetImageMso("WrapText", 16,
| 16)
| .Style = msoButtonIconAndCaption
| End With
| End Sub
|
| And it works. Also, I'm trying the following code:
|
| Public Sub commandBarsTest()
| Dim cbar As Office.CommandBar
| Dim ctrl As Office.CommandBarControl
|
| Set cbar = CommandBars("Cell")
|
| For Each ctrl In cbar.Controls
| Debug.Print ctrl.ID, ctrl.Caption, _
| ctrl.Visible, ctrl.Enabled
| Next ctrl
| End Sub
|
| Both the "Toggle Word Wrap" and AutoSum are listed (after running OP's
| code to include it), but when using the popup in cell only the Toggle
| Word Wrap is there - not the AutoSum.
|
| It might have something to do with Control's ID property? This code
| works, meaning I see "Test" in the in-cell shortcut menu:
|
| Public Sub testControls()
| Dim cbar As Office.CommandBar
| Dim ctrl As Office.CommandBarControl
|
| Set cbar = CommandBars("Cell")
|
| Set ctrl = cbar.Controls.Add(ID:=1)
|
| ctrl.Visible = True
| ctrl.Enabled = True
| ctrl.Caption = "Test"
| End Sub
|
| On Feb 12, 11:06 am, "Jim Rech" <jrr...@live.com> wrote:
| > Very interesting. It appears that what we see after right-clicking a
cell
| > is not the "cell" commandbar. At least it is not the "cell" commandbar
we
| > can modified with code.
| >
| > After running your code run this:
| >
| > commandbars("cell").ShowPopup
| >
| > You should see AutoSum at the bottom. But notice that this commandbar
has
| > black font, not blue. And that it doesn't have the floatie thing on
top.
| >
| > --
| > Jim"WhytheQ" <Whyt...@gmail.com> wrote in message
| >
| >
news:50bb05d8-27fd-48b8-af0e-(E-Mail Removed)...
| > | In 2003 I could do the following:
| > |
| > | Application.CommandBars("Cell").Controls.Add
| > | msoControlSplitButtonPopup, 226
| > |
| > | .......and an Autosum control would be created in the Cell menu.
| > |
| > | (I found 226 by recording a macro of changing a menu)
| > |
| > | In 2007 the above line doesn't seem to work. Although it doesn't throw
| > | an error either! ...
| > |
| > | Any help greatly appreciated
| > |
| > | Regards
| > | JasonQ
|


 
Reply With Quote
 
WhytheQ
Guest
Posts: n/a
 
      13th Feb 2008
On 12 Feb, 18:48, "Jim Rech" <jrr...@live.com> wrote:
> >>It might have something to do with Control's ID property?

>
> I'd guess it's the Type property. *The autosum is of type
> msoControlSplitButtonPopup and that is not listed among the types the
> commandbar controls Add method supports per Help. *Nevertheless Excel 2003
> did support it and Excel 2007 does only on the 'shadow' cell menu. *Go
> figure.
>
> Thanks for the additional information.
>
> --
> Jim"ilia" <iasaf...@gmail.com> wrote in message
>
> news:e826dedc-104c-4380-a6ec-(E-Mail Removed)...
> | Yes, however I'm running this code from J-Walk's Power Programming:
> |
> | Sub AddToShortCut()
> | ' * Adds a menu item to the Cell shortcut menu
> | * *Dim Bar As CommandBar
> | * *Dim NewControl As CommandBarButton
> | * *DeleteFromShortcut
> | * *Set Bar = CommandBars("Cell")
> | * *Set NewControl = Bar.Controls.Add _
> | * * * *(Type:=msoControlButton, ID:=1, _
> | * * * * temporary:=True)
> | * *With NewControl
> | * * * *.Caption = "Toggle &Word Wrap"
> | * * * *.OnAction = "ToggleWordWrap"
> | * * * *.Picture = Application.CommandBars.GetImageMso("WrapText", 16,
> | 16)
> | * * * *.Style = msoButtonIconAndCaption
> | * *End With
> | End Sub
> |
> | And it works. *Also, I'm trying the following code:
> |
> | Public Sub commandBarsTest()
> | *Dim cbar As Office.CommandBar
> | *Dim ctrl As Office.CommandBarControl
> |
> | *Set cbar = CommandBars("Cell")
> |
> | *For Each ctrl In cbar.Controls
> | * *Debug.Print ctrl.ID, ctrl.Caption, _
> | * * * * * * * ctrl.Visible, ctrl.Enabled
> | *Next ctrl
> | End Sub
> |
> | Both the "Toggle Word Wrap" and AutoSum are listed (after running OP's
> | code to include it), but when using the popup in cell only the Toggle
> | Word Wrap is there - not the AutoSum.
> |
> | It might have something to do with Control's ID property? *This code
> | works, meaning I see "Test" in the in-cell shortcut menu:
> |
> | Public Sub testControls()
> | *Dim cbar As Office.CommandBar
> | *Dim ctrl As Office.CommandBarControl
> |
> | *Set cbar = CommandBars("Cell")
> |
> | *Set ctrl = cbar.Controls.Add(ID:=1)
> |
> | *ctrl.Visible = True
> | *ctrl.Enabled = True
> | *ctrl.Caption = "Test"
> | End Sub
> |
> | On Feb 12, 11:06 am, "Jim Rech" <jrr...@live.com> wrote:
> | > Very interesting. *It appears that what we see after right-clicking a
> cell
> | > is not the "cell" commandbar. *At least it is not the "cell" commandbar
> we
> | > can modified with code.
> | >
> | > After running your code run this:
> | >
> | > *commandbars("cell").ShowPopup
> | >
> | > You should see AutoSum at the bottom. *But notice that this commandbar
> has
> | > black font, not blue. *And that it doesn't have the floatie thing on
> top.
> | >
> | > --
> | > Jim"WhytheQ" <Whyt...@gmail.com> wrote in message
> | >
> | >news:50bb05d8-27fd-48b8-af0e-(E-Mail Removed)....
> | > | In 2003 I could do the following:
> | > |
> | > | Application.CommandBars("Cell").Controls.Add
> | > | msoControlSplitButtonPopup, 226
> | > |
> | > | .......and an Autosum control would be created in the Cell menu.
> | > |
> | > | (I found 226 by recording a macro of changing a menu)
> | > |
> | > | In 2007 the above line doesn't seem to work. Although it doesn't throw
> | > | an error either! ...
> | > |
> | > | Any help greatly appreciated
> | > |
> | > | Regards
> | > | JasonQ
> |





Hello Jim

Do you know if it is possible to alter the shadow menu?

Regards
JasonQ.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How 2 sort an autosum total list after adding items 2 autosum item akm Microsoft Excel Misc 0 30th May 2010 11:44 PM
Adding commands to the Excel 2007 Chart context menu Andreas Microsoft Excel Charting 1 23rd Jan 2009 08:15 PM
Adding Menu Items to excel 2007 Jeff Microsoft Excel Programming 6 4th Jun 2008 06:11 AM
Adding context menu to shapes in Excel 2007 =?Utf-8?B?Sko=?= Microsoft Excel Programming 0 2nd Jun 2007 12:28 PM
Excel 2000 autosum not adding correctly ProdigyNews Microsoft Excel Discussion 3 31st Jul 2005 11:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:19 AM.