学习了高手的帖子《使用VB6创建COM加载宏》http://club.excelhome.net/dispbbs.asp?BoardID=2&ID=174063&replyID=&skin=0,我想单击cbPop出现下拉菜单的同时,运行一个宏test2,用了下面代码,可是不知到怎样建立一个类模块处理这个事件,(仿照帖子中做的不成功),关于按钮单击事件的类模块(也不知这样说对不对)已经请教研究数日,仍为学会怎样解决恳请各位指教:
Dim cbPop As Office.CommandBarPopup
Set cbPop = xlapp.CommandBars("Worksheet Menu Bar").Controls.Add(Type:=msoControlPopup)
With cbPop
.Caption = "测试菜单"
.OnAction = "test2"
End With
Set ButtonEvent = New cbEvents
Set ButtonEvent.cbBtn = cbPop
处理事件的类模块中
Public WithEvents cbBtn As CommandBarButton
Private Sub cbBtn_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
On Error Resume Next
Select Case Ctrl.OnAction
Case "test1"
test1
Case "test2"
test2
Case "test3"
test3
End Select
CancelDefault = True
End Sub
[此贴子已经被作者于2007-10-31 13:43:04编辑过]