0
votes

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
2
Are you sure that you are quoting the Office version correctly? Office 15 = Office 2013 not Office 2010. Office 365 is version 16.Timothy Rylatt
When developing in Office the rule is always to write your code in the oldest version you need to support. References to the Office object libraries are automatically updated to newer libraries, but cannot go backwards. Just to be certain that this works for Office 2010 x86 going to Office 365 x64 I just installed an old project, and the ribbon worked flawlessly.Timothy Rylatt
Timothy: We are mainly on Office 2010, so I wrote the code for that, and despite the Office 15 Object Library thing, somehow everyone in the department with Office 2010 is to use the ribbon from my testing. The users with Office 365 are missing either the library (in the location it was before 365), or are missing it all together (which is what I seem to be finding). These installs are managed by a system I'm not familiar with so I dont know what they are removing during the install, or what they are installing v not.ProgrammingStrugglesAreReal
Also my machine seems to have the Office 2016 Object library as do a few others, but that seems to be related to very specific software a few of us in the department have licenses for, so I'm using a different test machine that does not have it. Lastly, is there anyway you can share code snippets for your project so I can make sure I'm not missing something obvious in my existing code.ProgrammingStrugglesAreReal
I cannot share the code, and it is not necessary as no code is required.Timothy Rylatt

2 Answers

0
votes

You do not need to use late binding to make the ribbon work under O365. Word will pick up the later object libraries automatically.

You will need to test all your code to ensure that it is 64 bit compatible, but that is a different issue.

For O365 the object libraries (.OLB) will be under C:\Program Files\Microsoft Office\root\Office16. The Office 16 library (MSO.dll) should be under C:\Program Files\Common Files\Microsoft Shared\OFFICE16. If they're not there you need to find out why.

There are some additional security options that system admins can set for O365 including disabling the use of macros. You need to check what options are being applied as part of the install and ensure that whoever is responsible for the rollout understands that you need to use macros.

You also need to ensure that the .dotm is stored in the folder designated as the Startup folder. You can check this in File | Options | Advanced | File Locations enter image description here

This location must be the same as the one listed for Startup in the Trusted Locations. By default it is C:\Users\UserName\AppData\Roaming\Microsoft\Word\STARTUP. You should note that the Startup folder under C:\Program Files\Microsoft Office\root\Office16\ is not a trusted location anymore (under Office 2010 it was an implicitly trusted folder and any .dotm located there would work regardless of the trusted folder settings).

0
votes

If this needs to be run on different machines, you can use code to find the Startup Folder on the particular machine. The user, though, will need to set that folder as a trusted location. Here is a macro that puts the path in a message.

    Sub ShowStartUpPath()
    ' Macro written by Charles Kenyon 2014-02-25
    ' Shows setting for Startup Folder location in Microsoft Word in a message box.
    '
      MsgBox _
        Prompt:="Your StartUp folder location is " & _
          Application.StartupPath & _
          "." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & ".", _
        Buttons:=vbOKOnly, _
        Title:="Current Startup Folder Setting Information"
    '
    End Sub