I am developing a PowerPoint add-in and would like to temporarily disable some of the Ribbon controls while the add-in application is running.
I have developed a solution that works as expected when the Add-In is enabled, but this is not really adequate, because it disables some commonly used controls, like SlideMaster, SlideSorter, etc.
I am using PowerPoint 2010.
Here is a sample XML which is well-formed:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab idMso="TabView">
<group idMso="GroupMasterViews" getVisible="GetVisible"/>
</tab>
</tabs>
</ribbon>
</customUI>
Here is a sample callback, taken from this SO answer:
Sub GetVisible(control As IRibbonControl, ByRef returnedVal As Boolean)
If TrapFlag Then
returnedVal = False ' control is hidden
Else:
returnedVal = True ' control is not hidden
End If
End Sub
When I navigate to the View
ribbon, an alert informs me that:
The macro cannot be found or has been disabled because of your security settings.
Presumably this is referring to the GetVisible
macro? My macro settings are:
- Enable all macros (not recommended)
- Trust access to the VBA project object model
I have been struggling with what I have found so far but so far unable to implement suggestions. Most answers are specific to Excel. I have not really found anything specific to PowerPoint, but figured it should not be terribly difficult to port code from one application to another, as I have done this for many other things in VBA.
I have also tried this method, but the SetCustomUI
is not available in PowerPoint at the Application
or Presentation
level, perhaps it is unique or only applicable to Visual Studio?
After quite a bit of trial & error, I believe I have a functional solution, although there are some things I am not certain about which I will describe below.
I have tested this in a PPTM file with a subroutine to control the public
TrapFlag
variable, which determines whether to hide/disable certain controls. I have also tested this in a PPAM where this flag is set when the application launches, not when the Add-In is loaded.This allows me to manipulate the RibbonUI at runtime.
Here is the XML:
Here is the VBA callbacks, generated from the CustomUI Editor application, modified as per my requirements.
Some uncertainties
xmlID
is necessary in this case. He uses that somehow which I cannot understand.group
as I use on thecommand
in the XML, so I use the taggetEnabled
for the commands, but I have to usegetVisible
for the groups. These are tied to the callback functionsEnableControl
andVisibleGroup
, respectively. In any case,VisibleGroup
seems to disable the groups, so functionally it is the same.getEnabled
tag will prevent hotkey and programmatic access to those commands that I disable.