Option Explicit
Dim oWD As Object
Implements IRibbonExtensibility2 '添加對(duì) IRibbonExtensibility 接口的引用
'啟動(dòng)
Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
Set oWD = Application
MsgBox "我的com加載項(xiàng)已經(jīng)成功加載!"
End Sub
'實(shí)現(xiàn)IRibbonExtensibility接口的唯一成員 GetCustomUI,此過(guò)程調(diào)用 GetRibbonXML 方法,正如其名稱所示,
'該方法將自定義 XML 返回到 GetCustomUI 方法,后者然后將自定義 XML 添加到功能區(qū)用戶界面以便在加載外接程序時(shí)實(shí)現(xiàn)它。
Public Function IRibbonExtensibility_GetCustomUI(ByVal RibbonID As String) As String
IRibbonExtensibility_GetCustomUI = GetRibbonXML()
End Function
'添加 XML 自定義標(biāo)記代碼
Public Function GetRibbonXML() As String
Dim sRibbonXML As String
sRibb"http://schemas.microsoft.com/office/2006/01/customui"" >" & _
"<ribbon>" & _
"<tabs>" & _
"<tab id=""CustomTab"" label=""sanjie"">" & _
"<group id=""SampleGroup"" label=""Sample Group"">" & _
"<button id=""Button"" label=""Insert Name"" size=""large"" imageMso=""HappyFace"" InsertCompanyName"" />" & _
"</group >" & _
"</tab>" & _
"</tabs>" & _
"</ribbon>" & _
"</customUI>"
GetRibbonXML = sRibbonXML
End Function
'控件回調(diào)的過(guò)程
Public Sub InsertCompanyName(ByVal control As IRibbonControl)
' Inserts the specified text at the beginning of a range.
Dim MyText As String
Dim MyRange As Object
Set MyRange = oWD.ActiveDocument.Range
MyText = ""http://www.officefans.net/""
' Inserts text at the beginning
' of the active document.
MyRange.InsertBefore (MyText)
End Sub
聯(lián)系客服