PC Review


Reply
Thread Tools Rate Thread

Custom commandbar (1 works, 1 doesn't)

 
 
Dale Fye
Guest
Posts: n/a
 
      3rd Dec 2007
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:="FilePrintPreview")
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.
 
Reply With Quote
 
 
 
 
Dave D-C
Guest
Posts: n/a
 
      3rd Dec 2007
Dale,
When I put the following into a standard module, they work.
I get error 400 when they are in the userform module.
>Public Sub FilePrintPreview()
>Public Sub Use_POC_Defaults()
>Public Sub Display_warnings()

D-C Dave

Dale Fye <(E-Mail Removed)> wrote:
>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).


>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).
>
>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.
>


 
Reply With Quote
 
Dale Fye
Guest
Posts: n/a
 
      3rd Dec 2007
Dave,

As it sits now, they are in a standard code module. When you say they work,
do you mean that when you run the FileMenu sub and then pop it up, that the
Print Preview command button gets checked? If so, I don't know what is
going on. What version are you using? I'm in 2003.

Dale

"Dave D-C" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dale,
> When I put the following into a standard module, they work.
> I get error 400 when they are in the userform module.
>>Public Sub FilePrintPreview()
>>Public Sub Use_POC_Defaults()
>>Public Sub Display_warnings()

> D-C Dave
>
> Dale Fye <(E-Mail Removed)> wrote:
>>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).

>
>>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).
>>
>>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.
>>

>



 
Reply With Quote
 
Dave D-C
Guest
Posts: n/a
 
      4th Dec 2007
Dale,
The module placement was a shot in the dark -- didn't pan out.
The PP command button does not get checked, the other two
(1st level) buttons do get checked. I added a Textbox and code
which just confirms your problem.
I'm XL97/WIN98. Good luck, Dave

If ctrl.State = msoButtonDown Then
UserForm1.TextBox1 = "down"
ElseIf ctrl.State = msoButtonUp Then
UserForm1.TextBox1 = "up"
Else
UserForm1.TextBox1 = "other"
End If

"Dale Fye" <(E-Mail Removed)> wrote:
>As it sits now, they are in a standard code module. When you say they work,
>do you mean that when you run the FileMenu sub and then pop it up, that the
>Print Preview command button gets checked? If so, I don't know what is
>going on. What version are you using? I'm in 2003.


 
Reply With Quote
 
Dave D-C
Guest
Posts: n/a
 
      4th Dec 2007
1st level -- that's probably the key, right?
Buttons on CommandBars (msoBarPopup's) work (show state), but
for some reason buttons on CommandBarControls (msoControlPopup's)
on CommandBars don't work.

Which isn't helpful, is it?

Dave D-C <(E-Mail Removed)> wrote:
>The PP command button does not get checked, the other two
>(1st level) buttons do get checked.


Dale Fye <(E-Mail Removed)> wrote:
>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).


>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).
>
>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.
>


 
Reply With Quote
 
Dale Fye
Guest
Posts: n/a
 
      4th Dec 2007
Had not thought of that.

So maybe I just create a Print menu and when they click on the Print on the
top level menu, I popup the print menu as a separate menu. I'll give it a
try and see what happens.

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

email address is invalid
Please reply to newsgroup only.



"Dave D-C" wrote:

> 1st level -- that's probably the key, right?
> Buttons on CommandBars (msoBarPopup's) work (show state), but
> for some reason buttons on CommandBarControls (msoControlPopup's)
> on CommandBars don't work.
>
> Which isn't helpful, is it?
>
> Dave D-C <(E-Mail Removed)> wrote:
> >The PP command button does not get checked, the other two
> >(1st level) buttons do get checked.

>
> Dale Fye <(E-Mail Removed)> wrote:
> >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).

>
> >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).
> >
> >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.
> >

>
>

 
Reply With Quote
 
Dale Fye
Guest
Posts: n/a
 
      4th Dec 2007
Dave,

That did it. It obviously is not as elegant as the other method, but it
solves the immediate problem. Thanks for seeing what I couldn't.

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

email address is invalid
Please reply to newsgroup only.



"Dave D-C" wrote:

> 1st level -- that's probably the key, right?
> Buttons on CommandBars (msoBarPopup's) work (show state), but
> for some reason buttons on CommandBarControls (msoControlPopup's)
> on CommandBars don't work.
>
> Which isn't helpful, is it?
>
> Dave D-C <(E-Mail Removed)> wrote:
> >The PP command button does not get checked, the other two
> >(1st level) buttons do get checked.

>
> Dale Fye <(E-Mail Removed)> wrote:
> >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).

>
> >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).
> >
> >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.
> >

>
>

 
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
commandbar control works on some computers, not others josh Microsoft Excel Programming 1 22nd Jan 2010 08:58 PM
Commandbar works first pass, but not thereafter =?Utf-8?B?RGFsZSBGeWU=?= Microsoft Excel Programming 3 25th Oct 2007 07:41 PM
Custom Commandbar doesn't appear when opening or creating a new email Karsten_Markmann Microsoft Outlook VBA Programming 2 19th Jul 2006 06:26 AM
Office code works in Access, not in Outlook : re CommandBar Composer Microsoft Outlook VBA Programming 2 5th Apr 2005 11:00 PM
Custom Commandbar Stefano Condotta Microsoft Excel Programming 2 3rd Mar 2005 07:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:52 AM.