PDA

View Full Version : Custom button sometimes won't load to ribbon through xml



cplindem
10-23-2014, 01:37 PM
Hi,
I have a macro which is called by a custom button I added to the ribbon. The button is added by the customUI.xml file within my add-in (xlam file). I followed Ron de Bruin's guide (http://www.rondebruin.nl/win/s2/win001.htm). Microsoft also has their own documentation (http://msdn.microsoft.com/en-us/library/ee390805(v=office.11).aspx).

It usually works great. But sometimes the button disappears (i.e. it does not load). This seems to occur when I open a csv file directly (without Excel already open). My suspicion is that the call to load the button through xml fires before all workbook objects have loaded (because it's a csv file perhaps). Thus the button does not appear.

I found further explanations of this issue in a few old posts by user ZVI:
Problem with Auto Open Macro (http://www.mrexcel.com/forum/excel-questions/395270-problem-auto-open-macro.html#post1967868)
Find workbook name when macro run in add-in file (http://www.vbaexpress.com/forum/showthread.php?30552-Find-workbook-name-when-macro-run-in-add-in-file&p=205472#post205472)
Excel add-in does not load properly. (http://www.mrexcel.com/forum/excel-questions/471610-excel-add-does-not-load-properly-4.html)

I know I'm not allowed to PM him directly with this question. But I was hoping someone might know a solution. He suggests using Application.OnTime in a Workbook_Open() sub to trigger, because it will wait for the objects to load. I'm not sure I can follow his suggestions, because they are of course directly within VBA, and my code is triggered in the xml file. I don't know how to accomplish the same thing in xml.


Any ideas?

Aflatoon
10-24-2014, 05:31 AM
You can't control when the Ribbon loads, although if you have stored a Ribbon object using the onLoad callback, you could certainly invalidate it using OnTime.

Personally, I am not certain it's the same issue - can you share the XML from CustomUI plus any relevant callbacks?

cplindem
10-24-2014, 08:50 AM
Here's the xml:


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="RibbonControl.Onload">
<ribbon>
<tabs>


<tab idMso="TabHome" >
<group id="customGroup1" label="Banner Formatting" insertAfterMso="GroupEditingExcel">


<button id="customButton1" label="Auto Format" size="large"
onAction="Format" imageMso="HappyFace" />


</group>
</tab>


</tabs>
</ribbon>
</customUI>



The created button calls a simple macro called "format":


Sub Format(control As IRibbonControl)

FormattingOptions.Show

End Sub


which brings up a user form.