Commandbar disappears in Outlook

  • Thread starter Lutz Kretzschmar [MSFT]
  • Start date
L

Lutz Kretzschmar [MSFT]

I am writing an Outlook 2003 addin in VB6 and am adding a submenu in
the Tools menu. This submenu has four items on it (buttons).
Everything works fine as expected and all events fire.

I then go into Tools > Customize. I click on the Tools main menu and
then drag my created submenu onto another toolbar or onto the menubar
(makes no difference). Now the submenu items either disappear, or they
don't fire any events ( I can't tell when either one will happen,
mostly they just disappear).

I do process the OnUpdate message to retrieve the controls, but the
FindControl() function does not find the controls anymore.

I've run the PrintAllCbarInfo() function from Randy's book in the
OnUpdate after enhancing it to also print items on submenu's and sure
enough, the items are gone.

Any ideas?

- Lutz
 
K

Ken Slovak - [MVP - Outlook]

Are you using a unique Tag property for the menu item you create?

I created a button in the View menu with a Tag = "ExplShowGridView0". I then
ran this VBA code:

Sub testmovecbs()
Dim oButton As Office.CommandBarButton
Dim oBar As Office.CommandBar

Set oBar = Application.ActiveExplorer.CommandBars.Item("Menu Bar")

Set oButton = oBar.FindControl(, , "ExplShowGridView0", , True)
Debug.Print oButton.Caption
End Sub

As expected the debug.print statement printed the Caption of the button I
had added.

I then right-clicked on the main menu bar and in customize I dragged the
button to the Go menu. I then re-ran the code and it again found the button.

I set a breakpoint in the code that handles the button (a VB 6 project)
after moving the button to the Go menu and the Click event still fired and I
still trapped it.

If a unique Tag doesn't solve your problem show us your code for creating
the button.

FWIW, I didn't have to handle OnUpdate, the button still works and still can
be found just by using the Tag property.
 
L

Lutz Kretzschmar [MSFT]

I ran this code:

Sub CreateSubmenu()
Dim oToolMenu As CommandBarPopup
Set oToolMenu =
ActiveExplorer.CommandBars.ActiveMenuBar.FindControl(msoControlPopup,
30007, , True) ' Tools menu
If Not oToolMenu Is Nothing Then
Set m_projMenu =
ActiveExplorer.CommandBars.ActiveMenuBar.FindControl(msoControlPopup,
, "MyMenu", False, True)
If Not m_projMenu Is Nothing Then
m_projMenu.Delete
End If

Set m_projMenu = oToolMenu.Controls.Add(msoControlPopup, , , ,
True)
m_sProjectMenuCaption = "My Menu"
m_projMenu.Caption = "A MenuItem"
m_projMenu.BeginGroup = True
m_projMenu.Tag = "MyMenu"

Set m_SubButton = m_projMenu.Controls.Add(msoControlButton, ,
, , True)
With m_SubButton
.Caption = "SecondLevel Button"
.Style = msoButtonAutomatic
.Tag = "SecondButton"
.Visible = True
.Enabled = True
End With
End If
End Sub


Sub testmovecbs()
Dim oButton As Office.CommandBarButton
Dim oBar As Office.CommandBar

Set oBar = Application.ActiveExplorer.CommandBars.Item("Menu Bar")

Set oButton = oBar.FindControl(, , "SecondButton", , True)
Debug.Print oButton.Caption
End Sub


Then I used Tools > Customize to move the menu to a toolbar. Then the
testmovecbs function did not find it (probably expected as it is now
on a toolbar). Do I have to iterate over all toolbar and menubars to
find it?

- Lutz
 
K

Ken Slovak - [MVP - Outlook]

I wonder if using CommandBars.ActiveMenuBar.FindControl is returning
something different than what is returned by explicitly polling
CommandBars("Menu Bar")?

The other thing to check is if you can find the button control after moving
it if you put it directly on the Tools menu and not under your own
CommandBarPopup control.
 
K

Ken Slovak - [MVP - Outlook]

One other thing I can think of that would bypass the entire problem is to
just lock the buttons or toolbars or popups you create. Then the user can't
move them in Customize mode. Of course you'd have to do that on a CommandBar
basis, so it works best if used on your own toolbar/menu but you can set
CommandBar.Protection's msoBarNoCustomize bit. It's a bit-wise OR, so get
the current value of Protection and OR it with msoBarNoCustomize (1).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top