LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Custom commandbar (1 works, 1 doesn't)

HELP. Maybe someone else can see what I'm missing. I've got two custom
(popup) command bars in my application. These are commandbars are created in
a forms Initialize event, using the following code (I've removed a bunch of
the other options to test this, and it still is not working).

Sub FileMenu()

Dim CmdBar As Office.CommandBar
Dim CmdBarSub As CommandBarControl
Dim ctrl As Office.CommandBarControl

On Error Resume Next
Application.CommandBars("MyFile").Delete
On Error GoTo FileMenuError

Set CmdBar = Application.CommandBars.Add(Name:="MyFile", _
Position:=msoBarPopup, _
temporary:=True)
'Create the File Print menu options
Set CmdBarSub = CmdBar.Controls.Add(Type:=msoControlPopup)
With CmdBarSub
.Caption = "Print"
End With
Set ctrl = CmdBarSub.Controls.Add(Type:=msoControlButton)
With ctrl
.Caption = "Preview before print"
.OnAction = "FilePrintPreview"
.Tag = "FilePrintPreview"
'.State = msoButtonUp
End With

FileMenuExit:
Debug.Print "File menu built, no errors!"
Exit Sub

FileMenuError:
Debug.Print "File menu error!"

End Sub

Sub OptionsMenu()

Dim CmdBar As Office.CommandBar
Dim ctrl As Office.CommandBarControl

On Error Resume Next
Application.CommandBars("MyOptions").Delete
On Error GoTo 0

Set CmdBar = Application.CommandBars.Add(Name:="MyOptions", _
Position:=msoBarPopup, _
temporary:=True)

Set ctrl = CmdBar.Controls.Add(Type:=msoControlButton)
With ctrl
.Caption = "Use default POC data"
.OnAction = "Use_POC_Defaults"
.Tag = "Use_POC_Defaults"
End With

Set ctrl = CmdBar.Controls.Add(Type:=msoControlButton)
With ctrl
.Caption = "Display warnings!"
.OnAction = "Display_warnings"
.Tag = "Display_warnings"
End With

Exit Sub

OptionsMenuError:
Debug.Print Err.Number, Err.Description

End Sub

Both of these initialize properly and display properly when the user clicks
on one of two labels on my userform. However, the Options menu is working
properly and the File menu is not. They are displayed using the following
lines of code when a user clicks on one of two labels (that works properly).
I realize that the

Application.Commandbars("MyFile").ShowPopup
Application.Commandbars("MyOptions").ShowPopup

In the Options menu, when I click on the Use_POC_Defaults or
Display_warnings items, it toggles the state of that option correctly (see
code below), and the checkmark in front of the commandbarbutton is either
checked or unchecked the next time I open that commandbar. However, in the
File menu, when I click on "Print", and then select "Preview before print"
the FilePrintPreview subroutine fires, it changes the state value of that
command bar item (I've tested this by printing the state value before and
after that line of code), but does not visibly show the check mark in front
of the "Preview before print" item.

I've exported the text to VB, and imported it into another workbook to test
it there, and both menus function identically in the new workbook as well.

Public Sub FilePrintPreview()

Dim ctrl As CommandBarButton

'Changes the buttons state from Down-Up or Up-Down
Set ctrl = Application.CommandBars.FindControl(Tag:="FilePrin tPreview")
ctrl.State = IIf(ctrl.State = msoButtonDown, msoButtonUp, msoButtonDown)

End Sub

Public Sub Use_POC_Defaults()

Dim ctrl As CommandBarButton

'Changes the buttons state from Down-Up or Up-Down
Set ctrl = Application.CommandBars.FindControl(Tag:="Use_POC_ Defaults")
ctrl.State = IIf(ctrl.State = msoButtonDown, msoButtonUp, msoButtonDown)

End Sub
Public Sub Display_warnings()

Dim ctrl As CommandBarButton

'Changes the buttons state from Down-Up or Up-Down
Set ctrl = Application.CommandBars.FindControl(Tag:="Display_ warnings")
ctrl.State = IIf(ctrl.State = msoButtonDown, msoButtonUp, msoButtonDown)

End Sub

--
Don''t forget to rate the post if it was helpful!

Email address is not valid.
Please reply to newsgroup only.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Commandbar works first pass, but not thereafter Dale Fye Excel Programming 3 October 25th 07 07:41 PM
Custom commandbar, submenu questions Dale Fye Excel Programming 2 October 24th 07 06:22 PM
custom commandbar questions ckoch Excel Programming 1 February 12th 06 08:53 AM
Custom Commandbar Stefano Condotta Excel Programming 2 March 3rd 05 07:00 PM
Value of ComboBox on Custom CommandBar Kevin Excel Programming 4 January 15th 04 10:25 PM


All times are GMT +1. The time now is 05:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"