First post here, and also still learning VB so be gentle :).
I'm trying to understand how to late bind the Word Ribbon to a .dotm file.
I have a large number of users working in the Windows 10 (64 bit) platform using Office 2010 (32 bit), but we are transitioning to Office 365 (64 bit) in the next few months.
Both versions support ribbon customization using XML and VB. I'm trying to do the following:
- Create a Custom Ribbon
- Add various buttons, etc with custom images
- When each button is clicked it runs a macro
The .dotm file will be distributed to each users machine to one of the trusted locations so that the ribbon loads each time a word session is opened and that the macros run when clicked.
I have a working prototype for Office 2010, but the same file in Office 365 does not work due to missing references to the Microsoft Office 15 Object library
. From my understanding by "late binding" rather than "early binding", I can solve this problems since I wont be referencing the Microsoft Office 2015 object library
directly and when Word loads it will look to whatever reference library the computer has and uses to initialize the Ribbon.
I see I need to change the code to reference the ribbon as an Object
, but am not sure what the specific call to the Word Ribbon customization needs to be (and how to tie everything together). Looking through the various MSDN library links hasn't helped, its mainly just confused me further.
I've posted my generalized code below. Any help and advice would be appreciated.
The XML file looks like this
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Onload">
<ribbon>
<tabs>
<tab id="CustomTab1" label="Tab1">
<group id="Grp1" label="Group1" >
<button id="Grp1Btn1" size="large" label="Button1" image="Button1Image" onAction="Button1Clicked"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Then within the Project\Microsoft Word Objects\ThisDocument
I have the code that loads the Custom Ribbon, and then links the button click to the appropriate macro.
Option Explicit
Public myRibbon as IRibbonUI
'This is the link to the XML file so the custom ribbon loads at startup
Sub Onload(Ribbon as IRibbonUI)
Set myRibbon = Ribbon
End Sub
'Code for a single button which then runs a macro
Sub Button1Clicked(ByVal control as IRibbonControl)
Macro.Button1
End Sub
'Each button has its own Sub like this one, just with an different name and link to its macro
Then under Project\Modules\Macro
, I have all the code associated with each macro, like this:
Sub Button1()
MsgBox Prompt:="At this point Macro 1 would run, but for this example, all you get is this silly dialog box", Title:="Button 1 Success"
End Sub