Shortcut menu - submenus

X

XP

Using Office 2007 and Win XP;

I have a shortcut menu that has a couple menus on it, so when you hover on
the menu, a sub menu appears.

Problem is, everytime I hover on a menu, then hover over another menu, then
return to hover over the first menu again, the submenu doubles in size, only
with blanks.

I have a function I call that deletes the main menu, then re-builds it on
each call, and this works fine; but apparently while the main menu is held
open and the user switches between menu items, they are not rebuilt.

Sorry, I know this probably sounds a little flakey; if unclear please post
back and I will try to explain better. I guess I need to delete all the
submenu items each time the sub menus are opened; but how?

I hate to post all my code due to the complexity and length of the menu
system, but below at least is my function that builds one of the submenus. In
this example, the first time you hover, only the three items appear, on the
second hover, there would be six, then nine, etc. until the main menu is
closed, then it starts all over again...

Private Function ShortCutMenuPayroll(argShortCutMenu As String)
Dim oBar As CommandBar
Dim iX As Integer
Set oBar = Application.CommandBars(argShortCutMenu)
With oBar
iX = iX + 1
.Controls.Add Type:=msoControlButton
.Controls(iX).Caption = "Item One"
.Controls(iX).OnAction = "Macro1"
iX = iX + 1
.Controls.Add Type:=msoControlButton
.Controls(iX).Caption = "Item Two"
.Controls(iX).OnAction = "Macro2"
iX = iX + 1
.Controls.Add Type:=msoControlButton
.Controls(iX).Caption = "Item Three"
.Controls(iX).OnAction = "Macro3"
.Controls(iX).BeginGroup = True
End With
End Function

Thanks for your assistance!
 
X

XP

Hi, since initially posting, I solved my issue by adding the following to my
code:

If oBar.Controls(x).Controls.Count > 0 Then Exit Function

This way if the submenu has any controls on it, it won't be redrawn.
 
D

dbKemp

Using Office 2007 and Win XP;

I have a shortcut menu that has a couple menus on it, so when you hover on
the menu, a sub menu appears.

Problem is, everytime I hover on a menu, then hover over another menu, then
return to hover over the first menu again, the submenu doubles in size, only
with blanks.

I have a function I call that deletes the main menu, then re-builds it on
each call, and this works fine; but apparently while the main menu is held
open and the user switches between menu items, they are not rebuilt.

Sorry, I know this probably sounds a little flakey; if unclear please post
back and I will try to explain better. I guess I need to delete all the
submenu items each time the sub menus are opened; but how?

I hate to post all my code due to the complexity and length of the menu
system, but below at least is my function that builds one of the submenus. In
this example, the first time you hover, only the three items appear, on the
second hover, there would be six, then nine, etc. until the main menu is
closed, then it starts all over again...

Private Function ShortCutMenuPayroll(argShortCutMenu As String)
Dim oBar As CommandBar
Dim iX As Integer
Set oBar = Application.CommandBars(argShortCutMenu)
With oBar
iX = iX + 1
.Controls.Add Type:=msoControlButton
.Controls(iX).Caption = "Item One"
.Controls(iX).OnAction = "Macro1"
iX = iX + 1
.Controls.Add Type:=msoControlButton
.Controls(iX).Caption = "Item Two"
.Controls(iX).OnAction = "Macro2"
iX = iX + 1
.Controls.Add Type:=msoControlButton
.Controls(iX).Caption = "Item Three"
.Controls(iX).OnAction = "Macro3"
.Controls(iX).BeginGroup = True
End With
End Function

Thanks for your assistance!

Just build the menu once when you open the workbook and remove it when
you close the workbook.
 
X

XP

Thanks, but that doesn't work in this case; part of what you can't see in my
program is that it is tied to Workbook_Activate and Workbook_Deactivate
events; the menu necessarily needs to be built and rebuilt as the users
switch between books...
 

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