View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gareth[_6_] Gareth[_6_] is offline
external usenet poster
 
Posts: 158
Default Creating Option Entries in Excel Menu Bars using VB

Hi,

Do you mean the little tick/checkmark next to the menu item? If so you
need to set the .State property. You then change the State property
every time the button is clicked i.e. in the OnAction procedure.

See below,
HTH.

Sub createmycommandbar()

'-snippet

With NewSubItem
.Caption = "&Include Unapproved"
.OnAction = "fcnToggleIncludeUnapproved"
.Style = msoButtonCaption
.State = msoButtonDown
.TooltipText = "Click me"
.Tag = "SUPERUSERS,WRITEACCESSUSERS"
.BeginGroup = True
End With
'-end snippet

End Sub

Function fcnToggleIncludeUnapproved() As Boolean

Dim mySubItem As CommandBarControl

On Error GoTo RecreateCommandBar
Set mySubItem = _
Application.CommandBars(TOOLBAR_NAME) _
.Controls("Reports").Controls("Include Unapproved")
mySubItem.State = Not msoButtonUp

Set mySubItem = Nothing
fcnToggleIncludeUnapproved = True
Exit Function

RecreateCommandBar:
fcnCommandBarLoad 'this also applies the security
Resume

End Function

When I do this I actually store the state as a global boolean - just in
case I need to rebuild the command bar for some reason, I don't want the
status to reset.


Scott KBC wrote:
I wish to use VB in Excel to create an option entry in a menu that I have
created. For example, MS have done this with viewing the Formula Bar under
the View menu. Suggestions welcome, many thanks in advance.