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

cooler 2006-07-31 12:22:59
我参考:
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了。拜求达人解答。

望赐教!谢谢。

我的QQ是9355205,欢迎大侠指教。
...全文
771 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
cooler 2006-08-10
问题已经解决了。感谢大家支持。原因是,我的机器上居然没有OFFICE 9.0得LIB,我只找到8.0得LIB。
喔重安装了OFFICE2000就搞定了。
回复
非凡笨笨 2006-08-03
zdmchuner@126.com
回复
非凡笨笨 2006-08-03
我写过,我把油箱给你,发个消息我,我把源代码发给你,但是按钮的事件你要改下~~~
回复
cooler 2006-07-31
顶起,顶起
回复
发帖
Office开发/ VBA
创建于2007-08-27

4988

社区成员

其他开发语言 Office开发/ VBA
申请成为版主
帖子事件
创建了帖子
2006-07-31 12:22
社区公告
暂无公告