|
本帖最后由 EH2003 于 2016-3-18 21:41 编辑
因是即兴帖子回复需要审核,故只能重新开帖子了。
2、编写代码
在“项目”窗口中,右键单击“Connect”项并选择“查看代码”,删除在设计器代码窗口中自动生成的代码,将以下代码复制进去后保存。
Option Explicit
Public xlApp As Excel.Application
Implements IRibbonExtensibility '添加对 IRibbonExtensibility 接口的引用
Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
Set xlApp = Application '加载时
End Sub
Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Set xlApp = Nothing '卸载时
End Sub
'========================================================================
''实现IRibbonExtensibility接口的唯一成员 GetCustomUI,此过程调用 GetRibbonXML 方法,正如其名称所示,
'该方法将自定义 XML 返回到 GetCustomUI 方法,后者然后将自定义 XML 添加到功能区用户界面以便在加载外接程序时实现它。
'========================================================================
Public Function IRibbonExtensibility_GetCustomUI(ByVal RibbonID As String) As String
IRibbonExtensibility_GetCustomUI = GetRibbonXML()
End Function
'========================================================================
'添加 XML 自定义标记代码
'========================================================================
Public Function GetRibbonXML() As String
Dim sRibbonXML As String
sRibbonXML = "<customUI xmlns=""http://schemas.microsoft.com/office/2006/01/customui"" >" & _
"<ribbon><tabs>" & _
"<tab id=""CustomTab"" label=""网络ACC"">" & _
"<group id=""网络"" label=""网络连接"">" & _
"<button id=""Button01"" label=""网络连"" size=""large"" imageMso=""TableFormulaDialog""命令1"" />" & _
"</group >" & _
"</tab></tabs></ribbon></customUI>"
GetRibbonXML = sRibbonXML
End Function
'========================================================================
''控件回调的过程
'========================================================================
Public Sub 命令1(ByVal control As IRibbonControl)
Call Form1.Show
End Sub
|
评分
-
1
查看全部评分
-
|