Results 1 to 2 of 2

Thread: Ribbon and .dotm name collisions

  1. #1
    Seeker Mr Axolotl's Avatar
    Join Date
    Apr 2012
    Location
    Central Europe
    Posts
    7
    Articles
    0

    Ribbon and .dotm name collisions



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hello,

    I've been having a problem where a button's onAction invokes VBA code of the same name in a different addin. I have seen this problem in Word, but I imagine it would occur in Excel as well.

    The problem is easy to replicate. Create a minimal Foo1.dotm (probably Foo1.xlam would do the same) with the following user interface consisting of a single button

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <customUI onLoad="ribbonLoad" xmlns="htp://schemas.microsoft.com/office/2006/01/customui">
    <ribbon> 
        <tabs> 
          <tab id="Toolkit" label="Foo1"> 
            <group id="Foo1" label="Foo1"> 
              <box id="BoxX" boxStyle="vertical">
              <button id="Button001" imageMso="Piggy" 
                label="foo" 
                onAction="foo" /> 
              </box>
            </group> 
          </tab>
        </tabs> 
      </ribbon>
    </customUI>
    and with the following VBA code in a single module. (htp://... is intentional as this forum does not allow me to post links)

    Code:
    Option Explicit
    Public ribbon As IRibbonUI
    
    Private Sub ribbonLoad(arg As IRibbonUI)
        Set ribbon = arg
    End Sub
    
    Private Sub foo(arg As IRibbonControl)
        MsgBox "Foo1"
    End Sub
    When done, copy Foo1.dotm twice for Foo2.dotm and Foo3.dotm and change the XML
    Code:
    <tab id="Toolkit" label="Foo1">
    to Foo2 and Foo3 respectively

    and change the VBA
    Code:
    MsgBox "Foo1"
    to Foo2 and Foo3 as well.

    Code:
    onAction="foo"
    should remain the same in all three places.

    In total, there should be three .dotm files. My hope would be that clicking the Foo button in the Foo1 addin would display Foo1, Foo2 in the Foo2 addin, and so on. However, all three Foo buttons apparently execute the same program in the first Foo1 addin, and all display Foo1.

    Clearly, a solution is not to have any such name conflicts. The problem is that the other addins participating in this are not under my control, and there is no guarantee that this sort of thing will not happen again when the user installs another addin.

    What I think I need is to be able to write
    Code:
    onAction="Foo1.Module.foo"
    that is, a fully qualified name, so that I could unambiguoisly specify which foo is to be run. But that does not seem to work.

    Suggestions are very welcome. Namespaces?
    Last edited by Mr Axolotl; 2014-03-10 at 10:10 PM. Reason: forgot a key detail

  2. #2
    Acolyte Andy Pope's Avatar
    Join Date
    Mar 2011
    Location
    London, England
    Posts
    38
    Articles
    0
    I tested in excel using addins but the same should hold for word dotm files.

    In foo2.xlam I modified the onAction to include workbook name

    Code:
    onAction="foo2.xlam!foo"
    Cheers
    Andy

    www.andypope.info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •