拜求做过excel的add-in的高手解答,我无法在ADD-IN中添加excel的按钮事件!在线等回复中
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了。拜求达人解答。
望赐教!谢谢。
相关推荐
配电网正常重构,孤岛划分及故障重构
配电网正常重构,孤岛划分及故障重构
【AIGC专栏】Excel集成ChatGPT实现的效果
在使用ChatGPT的过程中,我们需要填写相应的GPT的API Key,获取API Key 我们需要在 https://platform.openai.com 中获取。
配电网的正常与故障重构中的孤岛划分技术探讨,配电网运行优化策略研究:正常重构、孤岛划分与故障重构应用分析,配电网正常重构,孤岛划分及故障重构 ,配电网重构;孤岛划分;故障重构,配电网智能重构策略:正常
配电网的正常与故障重构中的孤岛划分技术探讨,配电网运行优化策略研究:正常重构、孤岛划分与故障重构应用分析,配电网正常重构,孤岛划分及故障重构 ,配电网重构;孤岛划分;故障重构,配电网智能重构策略:正常与故障孤岛划分管理
配电网的正常与故障重构策略:孤岛划分技术的应用及其实践探讨,配电网正常重构,孤岛划分及故障重构 ,核心关键词:配电网正常重构; 孤岛划分; 故障重构;,配电网智能重构策略:正常与故障孤岛划分管理
配电网的正常与故障重构策略:孤岛划分技术的应用及其实践探讨,配电网正常重构,孤岛划分及故障重构 ,核心关键词:配电网正常重构; 孤岛划分; 故障重构;,配电网智能重构策略:正常与故障孤岛划分管理
配电网重构技术:正常重构、孤岛划分及故障重构的Python实现与应用
内容概要:本文详细介绍了配电网重构技术,涵盖正常重构、孤岛划分以及故障重构三个主要方面。首先,在正常重构部分,作者通过Python代码展示了如何利用Prim算法进行最小损耗拓扑的选择,确保配电网在低负荷时期能够达到最佳的供电效率。接着,针对孤岛划分,文中提供了基于深度优先搜索(DFS)的方法,用于确定分布式电源在主网断电时的供电范围,强调了电源点之间的电气连接管理。最后,对于故障重构,采用遗传算法来优化故障发生时的负荷恢复和开关操作,确保快速有效地隔离故障区并恢复正常供电。 适用人群:从事电力系统研究与开发的技术人员,尤其是对配电网重构感兴趣的工程师和技术爱好者。 使用场景及目标:适用于希望深入了解配电网重构机制及其具体实现方法的专业人士。目标是在面对电网异常情况时,能够运用先进的算法和技术手段提高供电系统的稳定性和可靠性。 其他说明:文中不仅提供了具体的Python代码实例,还讨论了一些实际工程项目中可能会遇到的问题及解决方案,如环网约束、负荷均衡等。此外,文章强调了配电网重构技术正朝着智能化方向发展,未来将更加自动化和高效化。 适合人群:具备一定编程基础,特别是熟悉Pytho


