Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a PPT Add-In which may fail if a certain ViewType is not maintained.

I do not see any PPTEvent which I could trap the change and prevent it (although, if this is possible, please advise!). So I have been playing with the Ribbon/CommandBars attempting to disable or hide certain controls pertaining to the ViewType.

I have identified the controls by Id and I attempt to set their .Visible property to False, or alternatively, to .Enabled = False, but neither seems to have any affect. The controls are still visible, and clicking on them still executes.

This example I would try to disable the Slide Sorter control. This prevents VBE from Execute the Button, but it does not disable the button's action as far as the user might still click it, it still executes.

Sub DisableViewChange()

    Dim cBar As CommandBar
    Dim ctrl As CommandBarControl

    Set cBar = CommandBars("View")

    Set ctrl = cBar.FindControl(Id:=738)
        ctrl.Visible = True
        ctrl.Enabled = False
    Set btn = ctrl
        btn.Execute



    Set cBar = Nothing
    Set btn = Nothing
    Set ctrl = Nothing

End Sub

Update to include pics of the elements I would like to disable/hide/remove:

enter image description here

share|improve this question
Could you add screen shot presenting view type and control which you want to switch off?? I'm not running English version of PP and it would be easier to get your situation. – KazJaw May 31 at 19:04
@KazJaw see screenshot above, let me know if that is enough information. – David Zemens May 31 at 19:19
thanks, let me think now :) – KazJaw May 31 at 19:20
I've just found out in my notes that you can't modify Ribbon buttons from VBA, it is required to change it in file's XML code. However, that could be possible to change behaviour of buttons using VBA but I can't find the solution :( – KazJaw May 31 at 19:54
I figured it was a Ribbon/XML thing... I have played with Ribbon extensibility but it was several months ago. I'm not terribly familiar with Ribbon, will that be a File-specific XML that I could make to a PPAM file? – David Zemens May 31 at 20:03
show 2 more comments

2 Answers

You can definitely modify the XML of a specific document to remove certain ribbon elements from the ribbon - I have done a huge amount of this. You should investigate using the Custom UI Editor which will open up the document and allow you to modify the XML of your selected ribbon groups by using the Visible = False modifier. Then, you should be able to save the Add-In and when it's loaded into memory it will hide the parts you've specified, preventing your crash.

This was useful for me a while ago: http://gregmaxey.mvps.org/word_tip_pages/customize_ribbon_main.html

There are Microsoft XML Schemas for each of the Office applications (which I can't find now - but definitely exists).

I hope that's some help.

share|improve this answer
Thanks, I do have the Custom UI editor so perhaps I will give that a try. – David Zemens May 31 at 22:55
up vote 0 down vote accepted

Red's suggestion above was very helpful. With some (errr... a lot) of trial and error, I was able to make some tweaks to the Ribbon. I present this answer in hopes that my trial and error will be useful to someone else who is equally unfamiliar with XML:

I disable several commands that I was looking to disable, that was relatively easy:

<commands>
    <command idMso="ViewSlideSorterView" enabled="false"/>
    <command idMso="ViewNotesPageView" enabled="false"/>
    <command idMso="ViewSlideShowReadingView" enabled="false"/>
    <command idMso="ViewSlideMasterView" enabled="false"/>
    <command idMso="ViewHandoutMasterView" enabled="false"/>
    <command idMso="ViewNotesMasterView" enabled="false"/>
    <command idMso="WindowNew" enabled="false"/>
</commands>

Since I am fussing with the XML, I decide also to migrate my add-in's commands from a legacy CommandBar (under the Add-Ins Tab group) to a custom ribbon tab, so this XML also contains a working example of a new Tab, which consists of a Group, a menu, and a few buttons in that menu.

Here is the validated XML including the disabled commands and the custom tab menu:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <commands>
        <command idMso="ViewSlideSorterView" enabled="false"/>
        <command idMso="ViewNotesPageView" enabled="false"/>
        <command idMso="ViewSlideShowReadingView" enabled="false"/>
        <command idMso="ViewSlideMasterView" enabled="false"/>
        <command idMso="ViewHandoutMasterView" enabled="false"/>
        <command idMso="ViewNotesMasterView" enabled="false"/>
        <command idMso="WindowNew" enabled="false"/>
    </commands>
    <ribbon startFromScratch="false">
        <tabs>
            <tab idMso="TabView">
                <group idMso="GroupPresentationViews" visible="true"/>
                <group idMso="GroupMasterViews" visible="true"/>
            </tab>
            <tab id="MyNewTab" label="My Tab Label">
                <group id="MyGroupMain" label="My Group Label">
                    <menu id="MyMenu" imageMso="HappyFace" size="large">
                        <button id="MyLaunchButton" label="Launch Tiger" onAction="macro1" />
                        <button id="MyInfoButton" label="Info" onAction="macro2" />
                        <button id="MyVersionButton" label="Version" onAction="macro3" />
                        <button id="MyHelpButton" label="Help" onAction="macro4" />
                    </menu>
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

I have not hooked my subroutines/macros in to these buttons yet, but that should not be terribly difficult.

I would not have been able to get through this without stumbling upon this link, which contains a batch of Excel files (for each Application) listing all of the menu items by type, id, relationship to other items, etc.

http://www.microsoft.com/en-us/download/details.aspx?id=6627

share|improve this answer
ah yes, that's the resource I was talking about but couldn't find! – Red 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.