PowerPoint vba - Refresh custom group on Ribbon does not work with empty screen

Veronica Stroomer 1 Reputation point
2022-04-01T06:48:09.4+00:00

I have three templates and for using these templates I am making an add-in with a custom Ribbon Tab. When PowerPoint is opened, and the add-in is loaded, the user only sees three buttons on the custom Tab (= the three templates) which can be used to start a new presentation. When template A is choosen to make a new presentation, group 1 gets visible on the custom Ribbon Tab. When the presentation is closed, the group disappears. And this also for 2 and 3. They are never visible all together.

The problem I run into now, is that the Ribbon does not refresh when there is no presentation already open (empty PPT screen) and I start a new presentation via my menu. Then my template-depended group does not appear in the Ribbon. This also happens when I open an existing presentation when there is an empty screen. I can also see in another way that the Ribbon is not updated because of the fact that after the Event, the Ribbon does not go back to the Home Tab.
When there is already a presentation on my screen it works fine. I can't figure out where it goes wrong. Here is my code:

I cannot post the xml, than my question is rejected. But here are some snippets

RibbonOnLoad

group id=MyCustomGroup1 label=Name getVisible=GetVisible tag=MyPersonalGroup1
And there I've added some custom buttons.
I also made "MyPersonalGroup2" and "MypersonalGroup3" like this.

VBA

Dim Rib As IRibbonUI
Dim MyTag As String

'Callback for customUI.onLoad
Sub RibbonOnLoad(ribbon As IRibbonUI)
    Set Rib = ribbon
End Sub

Sub getVisible(control As IRibbonControl, ByRef returnedVal)
Select Case control.Tag
    Case "MyPersonalGroup1"
        returnedVal = ActiveWindow.Selection.SlideRange.Design.Name = ("TemplateA")
    Case "MyPersonalGroup2"
        returnedVal = ActiveWindow.Selection.SlideRange.Design.Name = ("TemplateB")
    Case "MyPersonalGroup3"
        returnedVal = ActiveWindow.Selection.SlideRange.Design.Name = ("TemplateC")
End Select
End Sub

Class module called ApplicationEventClass:

Public WithEvents PPTEvent As Application

Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
    MyTag = Tag
    If Rib Is Nothing Then
        MsgBox "Error, restart your presentation"
    Else
        Rib.Invalidate
    End If
End Sub

I repeated this code for 'PPTEvent_AfterNewPresentation' 'PPTEvent_AfterPresentationOpen' 'PPTEvent_PresentationOpen' 'PPTEvent_PresentationClose' Is that necessary?

And this Module going with the code above:

Dim X As New ApplicationEventClass
Sub InitializePPTEvent()
Set X.PPTEvent = Application
End Sub

Help is very much appreciated!

Because no one reacted so far, I posted this question also on vbaexpress.com/forum/showthread.php?69782-PowerPoint-vba-Event-not-fired-when-screen-is-empty. My original question about GetVisible was on https://stackoverflow.com/questions/...creen-is-empty. Here I have had many help already, but not for this problem.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,497 questions
PowerPoint Management
PowerPoint Management
PowerPoint: A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.Management: The act or process of organizing, handling, directing or controlling something.
221 questions
0 comments No comments
{count} votes