首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 其他开发语言 >

Office 2007中VBA开发遇到的有关问题

2012-04-11 
Office 2007中VBA开发遇到的问题这是个右键菜单的函数。运行到oPopup.ShowPopup时会弹出如下错误。请问这是

Office 2007中VBA开发遇到的问题
这是个右键菜单的函数。运行到oPopup.ShowPopup时会弹出如下错误。请问这是怎么回事?谢谢!

Public Sub ShowRightMenue()
  Dim oPopup As CommandBar
  Dim oSubMenu As CommandBarPopup
  Dim oMenuItem As CommandBarControl
   
  Cancel = True
   
On Error Resume Next

  CommandBars("myRightMenu").Delete

On Error GoTo 0

  Set oPopup = CommandBars.Add("myRightMenu", msoBarPopup)
   
  Set oSubMenu = oPopup.Controls.Add(msoControlPopup)
  oSubMenu.Caption = "一级子菜单1"
  Set oMenuItem = oSubMenu.Controls.Add(msoControlButton)
  oMenuItem.Caption = "菜单项1-1"
  Set oMenuItem = oSubMenu.Controls.Add(msoControlButton)
  oMenuItem.Caption = "菜单项1-2"
  Set oMenuItem = oSubMenu.Controls.Add(msoControlButton)
  oMenuItem.Caption = "菜单项1-3"

  Set oSubMenu = oPopup.Controls.Add(msoControlPopup)
  oSubMenu.Caption = "一级子菜单2"
  Set oMenuItem = oSubMenu.Controls.Add(msoControlButton)
  oMenuItem.Caption = "菜单项2-1"
  Set oMenuItem = oSubMenu.Controls.Add(msoControlButton)
  oMenuItem.Caption = "菜单项2-2"
  Set oMenuItem = oSubMenu.Controls.Add(msoControlButton)
  oMenuItem.Caption = "菜单项2-3"

  oPopup.ShowPopup  

  oPopup.Delete
End Sub





[解决办法]


oPopup.ShowPopup

改成

Application.CommandBars("myRightMenu").ShowPopup

看看

热点排行