1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| Option Explicit
Dim oWD As Object
Implements IRibbonExtensibility
' Implement the IRibbonExtensibility Interface
' In this step, you implement the IRibbonExtensibilty interface's only member, GetCustomUI. Add the following procedure at the bottom of the code window.
Public Function IRibbonExtensibility_GetCustomUI(ByVal RibbonID As String) As String
IRibbonExtensibility_GetCustomUI = GetRibbonXML()
End Function
' This procedure calls the GetRibbonXML method that, as its name implies, returns the customization XML to the GetCustomUI method which then adds it to the ribbon to implement when the add-in loads.
' Retrieve the XML Customization Code
' In this step, you add the GetRibbonXML function. Here, the customization code is stored in a String variable that is returned to the GetCustomUI method.
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=""My Tab"">" & _
"<group id=""SampleGroup"" label=""Sample Group"">" & _
"<button id=""Button"" label=""Insert Company Name"" size=""large"" onAction=""InsertCompanyName"" />" & _
"</group >" & _
"</tab>" & _
"</tabs>" & _
"</ribbon>" & _
"</customUI>"
GetRibbonXML = sRibbonXML
End Function
' Add the Procedure That Is Called When You Click the Button
' Add the procedure that gets called when you click the custom button:
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 = "Microsoft Corporation"
' Inserts text at the beginning
' of the active document.
MyRange.InsertBefore (MyText)
End Sub |
Partager