
Need Help: Trouble adding a custom menu pick to a custom popup menu in VBA
Michael,
Comments interspersed in code.
' ---- Beginning Of Code -----
Sub NewMenuPickCode()
Dim cbarpop As CommandBarPopup
Dim cbpick As CommandBarButton
Dim oThisApp As Word.Application
Set oThisApp = Application
Set cbarpop = oThisApp.CommandBars("Menu Bar"). _
Controls.Add(msoControlPopup, , , , True)
cbarpop.Caption = "CustomTopMenuBar"
cbarpop.OLEMenuGroup = msoOLEMenuGroupContainer
cbarpop.OLEUsage = msoControlOLEUsageBoth
cbarpop.Visible = True
' You can't reference CustomTopMenuBar as a commandbar since
' it is defined as a commandbarpopup type.
' You already have a reference to the new commandbar popup, so
' just add the controls to CustomTopMenuBar as follows.
Set cbpick = cbarpop.Controls.Add(msoControlButton, , True)
cbpick.Caption = "CustomSubMenu1"
cbpick.Style = msoButtonCaption
cbpick.Visible = True
End Sub
' ---- End Of Code -----
--
Regards
Shyam Pillai
http://officetips.homepage.com
Please reply in newsgroup - No email replies .
...
Quote:
> I'm trying to add a custom popup menu to MS Word (seems to be working),
but
> I can't seem to add a custom menu button to that new custom popup menu.
> I've tried the following code in VBA. What am I doing wrong?
> Sub NewMenuPickCode()
> Dim cbarpop As CommandBarPopup
> Dim cbpick As CommandBarButton
> Dim oThisApp As Word.Application
> Set oThisApp = Application.Application
> Set cbarpop = oThisApp.CommandBars("Menu
> Bar").Controls.Add(msoControlPopup, , , , True)
> cbarpop.Caption = "CustomTopMenuBar"
> cbarpop.OLEMenuGroup = msoOLEMenuGroupContainer
> cbarpop.OLEUsage = msoControlOLEUsageBoth
> cbarpop.Visible = True
> ' This fails, but if I put "Tools" in place of "CustomTopMenuBar", it
> works fine.
> Set cbpick =
> oThisApp.CommandBars("CustomTopMenuBar").Controls.Add(msoControlButton, ,
> True)
> cbpick.Caption = "CustomSubMenu1"
> cbpick.Style = msoButtonCaption
> cbpick.Visible = True
> End Sub
> Thanks in advance for any help!
> -Michael