I am developping an add-in for Powerpoint 365 using the interop assemblies. Assemby version of Microsoft.Office.Interop.Powerpoint.dll is 15.0.4420.1017.

My application is registered to all the events provided by Microsoft.Office.Interop.PowerPoint.Application interface, such as PresentationOpen, AfterNewPresentation, WindowActivate, etc.

In a presentation (e.g. Presentation1.pptx), I inserted an hyperlink which links to an existing presentation file (e.g. Presentation2.pptx).

Whenever I access to Presentation2.pptx via this link (Ctrl+Click), PresentationOpen and PresentationAfterOpen events are not called at all. Only the WindowActivate event is fired.

However, when I open a presentation from the open menu or by double click on a presentation on the Windows Explorer, WindowActivate, PresentationOpen and PresentationAfterOpen events are fired in this order as expected.

I would have expected the same behavior in all open actions, but it doesn't seem to be the case.

I noticed that Application.ActivePresentation is already set to Presentation2.pptx when WindowActivate is called. I would have thought that this would be the case in or after PresentationOpen is called.

Do you know the reason why PresentationOpen and PresentationAfterOpen events are not fired in such case? Is there any workaround/best practice I should be aware of, or should I instead move part of my code in WindowActivate?

Snippet of code:

using Microsoft.Office.Interop.PowerPoint;

public partial class ThisAddIn
{
    public override void BeginInit()
    {
        Application.AfterDragDropOnSlide += AfterDragDropOnSlide;
        Application.AfterNewPresentation += AfterNewPresentation;
        Application.AfterPresentationOpen += AfterPresentationOpen;
        Application.AfterShapeSizeChange += AfterShapeSizeChange;
        Application.ColorSchemeChanged += ColorSchemeChanged;
        Application.PresentationBeforeClose += PresentationBeforeClose;
        Application.PresentationBeforeSave += PresentationBeforeSave;
        Application.PresentationClose += PresentationClose;
        Application.PresentationCloseFinal += PresentationCloseFinal;
        Application.PresentationNewSlide += PresentationNewSlide;
        Application.PresentationOpen += PresentationOpen;
        Application.PresentationPrint += PresentationPrint;
        Application.PresentationSave += PresentationSave;
        Application.PresentationSync += PresentationSync;
        Application.ProtectedViewWindowActivate += ProtectedViewWindowActivate;
        Application.ProtectedViewWindowBeforeClose += ProtectedViewWindowBeforeClose;
        Application.ProtectedViewWindowBeforeEdit += ProtectedViewWindowBeforeEdit;
        Application.ProtectedViewWindowDeactivate += ProtectedViewWindowDeactivate;
        Application.ProtectedViewWindowOpen += ProtectedViewWindowOpen;
        Application.SlideSelectionChanged += SlideSelectionChanged;
        Application.SlideShowBegin += SlideShowBegin;
        Application.SlideShowEnd += SlideShowEnd;
        Application.SlideShowNextBuild += SlideShowNextBuild;
        Application.SlideShowNextClick += SlideShowNextClick;
        Application.SlideShowNextSlide += SlideShowNextSlide;
        Application.SlideShowOnNext += SlideShowOnNext;
        Application.SlideShowOnPrevious += SlideShowOnPrevious;
        Application.WindowActivate += WindowActivate;
        Application.WindowBeforeDoubleClick += WindowBeforeDoubleClick;
        Application.WindowBeforeRightClick += WindowBeforeRightClick;
        Application.WindowDeactivate += WindowDeactivate;
        Application.WindowSelectionChange += WindowSelectionChange;
    }

    private void PresentationOpen(Presentation presentation)
    {
        // code executed if File -> Open, or presentation opened from file explorer
        // Not executed when presentation is opened from hyperlink
    }

    private void AfterPresentationOpen(Presentation presentation)
    {
        // code executed if File -> Open, or presentation opened from file explorer
        // Not executed when presentation is opened from hyperlink
    }

    private void WindowActivate(Presentation presentation, DocumentWindow documentWindow)
    {
        // code executed if File -> Open, presentation opened from file explorer OR when the presentation is opened from hyperlink in another presentation
    }

    ...
}
0

There are 0 best solutions below