Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
楼主: 事后诸葛亮

[已解决]VB中制作COM加载项时,如何添加子菜单

[复制链接]
发表于 2013-7-19 10:46 | 显示全部楼层
你把你的COM工程发我,我试下。
回复

使用道具 举报

 楼主| 发表于 2013-7-19 10:48 | 显示全部楼层
hwc2ycy 发表于 2013-7-19 10:46
你把你的COM工程发我,我试下。

COM工程.rar (7.49 KB, 下载次数: 18)
回复

使用道具 举报

发表于 2013-7-19 10:53 | 显示全部楼层
缺文件,你把所有的都打包上传。
回复

使用道具 举报

 楼主| 发表于 2013-7-19 10:54 | 显示全部楼层
hwc2ycy 发表于 2013-7-19 10:53
缺文件,你把所有的都打包上传。

自定义菜单COM加载项.rar (17.7 KB, 下载次数: 44)
回复

使用道具 举报

 楼主| 发表于 2013-7-19 10:54 | 显示全部楼层
不好意思 呵呵 就是生成DLL文件
回复

使用道具 举报

发表于 2013-7-19 11:04 | 显示全部楼层
QQ截图20130719110524.jpg

还是缺文件。
回复

使用道具 举报

发表于 2013-7-19 11:06 | 显示全部楼层
你添加了引用没有?
EXCEL和OFFICE的,另外,设置可有对?
回复

使用道具 举报

发表于 2013-7-19 11:10 | 显示全部楼层
   Dim WithEvents mn1 As Office.CommandBarButton
   Dim WithEvents mn2 As Office.CommandBarButton
原来的代码这里定死了,得改类型才行。
回复

使用道具 举报

 楼主| 发表于 2013-7-19 11:15 | 显示全部楼层
hwc2ycy 发表于 2013-7-19 11:10
Dim WithEvents mn1 As Office.CommandBarButton
   Dim WithEvents mn2 As Office.CommandBarButton
...


我也不知道怎么回事了。这是VB里面的原代码,你帮我弄一个吧。谢谢了。

   Dim oXL As Object
   Dim mnMain As Office.CommandBarPopup
   Dim WithEvents mn1 As Office.CommandBarButton
   Dim WithEvents mn2 As Office.CommandBarButton
   Dim WithEvents MyButton As Office.CommandBarButton

Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)

'    Dim mymenu As Object 'CommandBarControl
'    Dim mnMain As Object
'    Dim mn1 As Object, mn2 As Object
    On Error Resume Next

    Set oXL = Application
    oXL.CommandBars("Worksheet Menu Bar").Controls("提取功能").Delete
    Set mnMain = oXL.CommandBars("Worksheet Menu Bar").Controls.Add(Type:=msoControlPopup, Before:=11)
    mnMain.Caption = "提取功能"
    Set mn1 = mnMain.Controls.Add(Type:=msoControlButton, Before:=1)
    With mn1
        .Caption = "提取文件名"
        .OnAction = "!<" & AddInInst.ProgId & ">"
        .FaceId = 162
        '.Visible = True
    End With
    Set mn2 = mnMain.Controls.Add(Type:=msoControlButton, Before:=2)
    With mn2
        .Caption = "提取E表数据"
        .BeginGroup = True '增加间隔符
        .OnAction = "!<" & AddInInst.ProgId & ">"
        .FaceId = 300
        '.Visible = True
        With .Controls.Add(Type:=msoControlButton)
            .Caption = "子菜单一"
            .Visible = True
        End With
        With .Controls.Add(Type:=msoControlButton)
            .Caption = "子菜单二"
            .Visible = True
        End With
    End With
End Sub

回复

使用道具 举报

发表于 2013-7-19 11:18 | 显示全部楼层
  1.    Dim oXL As Object
  2.    Dim mnMain As Office.CommandBarPopup
  3.    Dim mnMain2 As Office.CommandBarPopup
  4.    Dim WithEvents mn1 As Office.CommandBarButton
  5.    Dim WithEvents mn2 As Office.CommandBarButton
  6.    Dim WithEvents MyButton As Office.CommandBarButton

  7.    Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
  8.     ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
  9.     ByVal AddInInst As Object, custom() As Variant)

  10.       
  11. '    Dim mymenu As Object 'CommandBarControl
  12. '    Dim mnMain As Object
  13.     'Dim mn1 As Object, mn2 As Object
  14.     On Error Resume Next
  15.    
  16.     Set oXL = Application
  17.     oXL.CommandBars("Worksheet Menu Bar").Controls("期末处理(K)").Delete
  18.     Set mnMain = oXL.CommandBars("Worksheet Menu Bar").Controls.Add(Type:=msoControlPopup, Before:=11)
  19.     mnMain.Caption = "期末处理(K)"
  20.     Set mn1 = mnMain.Controls.Add(Type:=msoControlButton, Before:=1)
  21.     With mn1
  22.         .Caption = "移动1"
  23.         .OnAction = "!<" & AddInInst.ProgId & ">"
  24.         .FaceId = 162
  25.         '.Visible = True
  26.     End With
  27.     Set mnMain2 = mnMain.Controls.Add(Type:=msoControlPopup, Before:=2)
  28.     With mnMain2
  29.         .Caption = "移动2"
  30.         .BeginGroup = True '增加间隔符
  31.         '.OnAction = "!<" & AddInInst.ProgId & ">"
  32.         '.FaceId = 300
  33.         '.Visible = True
  34.         Set mn1 = .Controls.Add(Type:=msoControlButton)
  35.                 With mn1
  36.                 .Caption = "子菜单1"
  37.                 .Visible = True
  38.                 End With
  39.         Set mn2 = .Controls.Add(Type:=msoControlButton)
  40.                 With mn1
  41.                 .Caption = "子菜单2"
  42.                 .Visible = True
  43.                 End With
  44.                
  45.         
  46.     End With
  47.    
  48.    End Sub
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-4 00:32 , Processed in 0.441353 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表