Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-11-2024, 05:09 AM
hank1234 hank1234 is offline How to reference a function from another .dotm file in Word custom ribbon XML? Windows 11 How to reference a function from another .dotm file in Word custom ribbon XML? Office 2016
Novice
How to reference a function from another .dotm file in Word custom ribbon XML?
 
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
  #2  
Old 08-11-2024, 04:47 PM
Guessed's Avatar
Guessed Guessed is offline How to reference a function from another .dotm file in Word custom ribbon XML? Windows 10 How to reference a function from another .dotm file in Word custom ribbon XML? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I would ALWAYS put the code you want the ribbon to execute in the same template. However, the concept I would try is to point your ribbon at a macro in the same template that does:
1. Check that the addin is loaded and if not, attempts to load it
2. If the addin is still not loaded, tell the user that it wasn't found or loaded
3. Calls the macro you wanted in that addin
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-12-2024, 06:49 AM
Italophile Italophile is offline How to reference a function from another .dotm file in Word custom ribbon XML? Windows 11 How to reference a function from another .dotm file in Word custom ribbon XML? Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

You can also add ribbon code to the styles manager that will add the button to the tab created by the ribbon manager template. You will need to modify the ribbon xml to make this work.

For your ribbon manager:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"
          xmlns:nsHost="rbnManager">
  <ribbon startFromScratch="false">
    <tabs>
      <tab idQ="nsHost:Company" label="Company">
        <group idQ="nsHost: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>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>
For your style manager:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"
          xmlns:nsClient="rbnManager">
    <tabs>
      <tab idQ="nsClient:Company">
        <group idQ="nsClient:newGroup">
          <button id="btnStyleManager" 
                  label="Paragraph Styles" 
                  onAction="ShowfrmParagraphStylesIfNecessary"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>
NOTE: I have used this method to add items to a custom ribbon that are specific to a particular document template, but I would hesitate to use this for two templates that are in the startup folder as it is not possible to control the order in which they are loaded.
Reply With Quote
  #4  
Old 08-13-2024, 02:41 AM
hank1234 hank1234 is offline How to reference a function from another .dotm file in Word custom ribbon XML? Windows 11 How to reference a function from another .dotm file in Word custom ribbon XML? Office 2016
Novice
How to reference a function from another .dotm file in Word custom ribbon XML?
 
Join Date: Sep 2020
Posts: 11
hank1234 is on a distinguished road
Default

Thank you, Italophile! Your suggestion led me to the following solution. I've implemented it in the main .dotm file (not necessary to put any in the secondary one). Here's the relevant code:

This is the relevant code:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"
          xmlns:nsHost="rbnManager"
          xmlns:nsClient="rbnManager">
  <ribbon startFromScratch="false">
    <tabs>
      <tab idQ="nsHost:Company" label="Company">
        <group idQ="nsHost: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>
        </group>
        
        <group idQ="nsClient:styleManagerGroup" label="Style Manager">
          <button id="btnStyleManager" 
                  label="Paragraph Styles" 
                  size="large"
                  imageMso="NewPageOneNote"
                  onAction="mStyleManager.ShowfrmParagraphStylesIfNecessary"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>
It would be ideal to have the xml separated (like in Italophile's post), but then I encountered that it's difficult to position the new group in the ribbon-tab. Is there a solution to the latter problem?
Reply With Quote
  #5  
Old 08-13-2024, 03:44 AM
Italophile Italophile is offline How to reference a function from another .dotm file in Word custom ribbon XML? Windows 11 How to reference a function from another .dotm file in Word custom ribbon XML? Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

If you are putting the xml in the one file then the use of nsHost, nsClient, and idQ is unnecessary. These are only required when adding items into an existing custom ribbon. See office addins - Add a custom Ribbon group to an existing custom Ribbon group in word 2007 - Stack Overflow
Reply With Quote
Reply

Tags
ribbon control, xml



Similar Threads
Thread Thread Starter Forum Replies Last Post
instance a new dotm file from a Word dotm file and save with new file name David Peck Word VBA 3 08-18-2023 06:47 AM
Dissociate instance of a custom ribbon, for documents based on the same dotm creation template? Ddadoo57 Word VBA 7 03-21-2023 05:34 AM
How to reference a function from another .dotm file in Word custom ribbon XML? Word Custom Ribbon In .dotm - How to edit/create? s0me0nesmind1 Word 6 04-16-2020 04:10 PM
How to reference a function from another .dotm file in Word custom ribbon XML? Custom ribbon button or shortcut for a specific function Nicobisgaard Word 6 04-22-2015 04:39 AM
Is it possible to add a custom macro button to the FILE tab of the ribbon in excel sbapabck Excel 2 04-11-2014 07:36 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft