View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default [Excel '03] check-box menu items and cell context menus don't disp

Hi Jack,

I don't quite follow what you're after but try the following for ideas

Dim mbFlag As Boolean
Const mTAG_2 As String = "TestTagBtn1"

Sub TestAdd()
CellMenu True
End Sub
Sub TestRemove()
CellMenu False
End Sub

Sub CellMenu(bAdd As Boolean)
Dim cPop As CommandBarPopup
Dim cBtn As CommandBarButton
Dim cBar As CommandBar
Const TAG_1 As String = "TestTagPop"

Set cBar = Application.CommandBars("Cell")
On Error Resume Next
Set cPop = Application.CommandBars.FindControl(Tag:=mTAG_1)
On Error GoTo 0
If Not cPop Is Nothing Then cPop.Delete


If bAdd Then
Set cPop = cBar.Controls.add(msoControlPopup, temporary:=True)
cPop.Caption = "Test menu"
cPop.Tag = mTAG_1
Set cBtn = cPop.Controls.add(msoControlButton)

With cBtn
.Caption = "Macro1"
.Style = msoButtonCaption
.OnAction = "Macro1"
.State = CLng(mbFlag) ' msoButtonDown/Up
.Tag = mTAG_2
End With


End If

End Sub

Sub Macro1()
Dim cBtn As CommandBarButton
mbFlag = Not mbFlag

On Error Resume Next
'If called by the button
Set cBtn = Application.CommandBars.ActionControl
On Error GoTo 0

'or

Set cBtn = Application.CommandBars.FindControl(Tag:=mTAG_2)

If Not cBtn Is Nothing Then
cBtn.State = CLng(mbFlag)
End If

MsgBox mbFlag

End Sub

Hopefully you will be able to toggle the tick aganst the Macro1 button on
the rt-click Cell menu

Regards,
Peter T

"Jack Hoxley [MVP]" <Jack Hoxley wrote in
message ...
Morning all,

I've been tasked with making some modifications to a VBA add-in for Excel
2003. Not my usual programming territory but so far so good except for one
thing:

In creating a short menu appended to the "Cell" Application.CommandBars

and
then, according to user input, setting the "State" property to either
MsoButtonState.msoButtonDown or MsoButtonState.msoButtonUp I don't get any
sort of visual indication of the menu item being selected or not.

By contrast, the exact same code (just hooked onto the main menu bar

instead
of the 'Cell' context menu) functions correctly and I get the appropriate
highlight and checkbox to show the menu item is/isn't selected.

I can't find any similar occurences online and I'm a little stumped. I
suppose the root cause is probably differences between the main menu and
context menu objects - I'm treating them as the same for now (all
Type:=msoControlButton and accessed via Office.CommandBarButton

instances).

It'd be greatly appreciated if someone could point me in the right

direction
for creating context menu entries with on/off visual indication :-)


Thanks in advance,
Jack