拜求做过excel的add-in的高手解答,我无法在ADD-IN中添加excel的按钮事件!在线等回复中

cooler 2006-07-31 12:21:26
我参考:
http://support.microsoft.com/default.aspx?scid=kb%3Bzh-cn%3B238228
【如何生成 VisualBasic 中 Office 2000 COM 加载宏】
进行自己的程序的开发。

其中ADD-IN的connect连接器核心代码如下:
Option Explicit

Dim oXL As Object
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)
On Error Resume Next
MsgBox "My Addin started in " & Application.Name

Set oXL = Application

Set MyButton = oXL.CommandBars("Standard").Controls.Add(1)
With MyButton
.Caption = "My Custom Button"
.Style = msoButtonCaption

' The following items are optional, but recommended.
' The Tag property lets you quickly find the control
' and helps MSO keep track of it when there is more than
' one application window visible. The property is required
' by some Office applications and should be provided.

.Tag = "My Custom Button"

' The OnAction property is optional but recommended.
' It should be set to the ProgID of the add-in, such that if
' the add-in is not loaded when a user presses the button,
' MSO loads the add-in automatically and then raises
' the Click event for the add-in to handle.

.OnAction = "!<" & AddInInst.ProgId & ">"

.Visible = True
End With

End Sub

Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As _
AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
On Error Resume Next
MsgBox "My Addin was disconnected by " & _
IIf(RemoveMode = ext_dm_HostShutdown, _
"Excel shutdown.", "end user.")

MyButton.Delete
Set MyButton = Nothing
Set oXL = Nothing
End Sub

Private Sub MyButton_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
MsgBox "Our CommandBar button was pressed!"
End Sub

问题就是,上面的第3行:
Dim withevents MyButton As Office.CommandBarButton

在我的VB里面编译不通过,报告【不是源事件对象】
只能改成:Dim MyButton As Office.CommandBarButton,才能通过。但是这样我又无法处理自己添加的按钮的点击事件了。
我已经查遍GOOGLE,MSDN,CSDN了。拜求达人解答。

望赐教!谢谢。
...全文
608 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cooler 2006-08-10
  • 打赏
  • 举报
回复
问题已经解决了。感谢大家支持。原因是,我的机器上居然没有OFFICE 9.0得LIB,我只找到8.0得LIB。
喔重安装了OFFICE2000就搞定了。
vansoft 2006-08-01
  • 打赏
  • 举报
回复
Implements IDTExtensibility2
Private Withevents MyButton As Office.CommandBarButton

試試,我做的成功的。
cooler 2006-07-31
  • 打赏
  • 举报
回复
求支持。顶起
cooler 2006-07-31
  • 打赏
  • 举报
回复
没有达人吗?

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧