View Single Post
 
Old 08-11-2024, 05:09 AM
hank1234 hank1234 is offline Windows 11 Office 2016
Novice
 
Join Date: Sep 2020
Posts: 11
hank1234 is on a distinguished road
Question How to reference a function from another .dotm file in Word custom ribbon XML?

I'm customising Word with two template files: Ribbon.dotm and StyleManager.dotm, and I'm facing a specific issue with XML referencing.

Setup:
  • Ribbon.dotm: Contains XML for custom ribbon and most of the VBA code
  • StyleManager.dotm: Contains a specific module/userform I want to access
  • Both .dotm files are in Word's startup folder
  • All code is present and functional, and the naming of .dotm files and subroutines is correct

The Issue:
XML in Ribbon.dotm defines buttons, most calling functions within Ribbon.dotm successfully
One button should call a function from StyleManager.dotm
The problem lies specifically in how to correctly reference a function in another .dotm file within the XML

When clicking the button that should call the StyleManager.dotm function, I get this error: "The macro cannot be found or has been disabled due to your macro security settings."

Here's the relevant part of the XML code where the issue occurs:
Code:
onAction="StyleManager.dotm!mStyleManager.ShowfrmParagraphStylesIfNecessary"/
The key question is: What is the correct XML syntax to reference a function in StyleManager.dotm from within Ribbon.dotm's XML?

Is there perhaps an alternative method to create a single Ribbon that incorporates buttons from multiple .dotm files? While I'm aware that the simplest solution would be to migrate the code from StyleManager.dotm into Ribbon.dotm, I'm particularly interested in exploring whether it's feasible to maintain the current file structure while achieving the desired functionality. Are there any advanced techniques or workarounds that could allow for this kind of cross-file referencing in the Ribbon XML?

This is the full XML code:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
  <ribbon startFromScratch="false">
    <tabs>
      <tab id="Company" label="Company">
        <group id="newGroup" label="New">
          <menu id="mnuMemo" 
                size="large" 
                label="Memo" 
                imageMso="NewPageOneNote">
            <button id="btnCreateMemo" 
                    label="New memo" 
                    onAction="mMemo.CreateNewMemo"/>
            <button id="btnEditMemo" 
                    label="Edit memo" 
                    onAction="mMemo.EditMemo"/>
          </menu>
          <!-- Button attempting to call function from StyleManager.dotm -->
          <button id="btnStyleManager" 
                  label="Paragraph Styles" 
                  onAction="StyleManager.dotm!mStyleManager.ShowfrmParagraphStylesIfNecessary"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>
Reply With Quote