Reputation: 1347
Is it possible in PowerPoint Interop used from C# to programatically select a slide master page into view, just like you would select a regular slide? Either by giving the ID of that master page or from the slide that has it as template.
I managed to switch the view to the slide master:
_pptApplication.ActiveWindow.ViewType = PpViewType.ppViewMasterThumbnails;
I tried selecting a slide first and then switching to the master view, but this instruction always places into view the first slide master page, not the one associated to the selected slide.
Likewise, I'd like to know if this is possible for notes, handouts and their masters.
Upvotes: 0
Views: 962
Reputation: 884
You need to use the method .Select() on a CustomLayout object in addition to setting .ViewType as you had already figured out.
Here are two examples:
using NetOffice.OfficeApi.Enums;
using NetOffice.PowerPointApi.Enums;
using System;
using PowerPoint = NetOffice.PowerPointApi;
namespace ExportSlides
{
class Program
{
static void Main(string[] args)
{
using (var app = PowerPoint.Application.GetActiveInstance())
{
SelectSlideMasterLayoutOfActiveSlide(app);
ActiveSlideMasterLayoutByIndex(app.ActivePresentation, 4);
}
}
private static void ActiveSlideMasterLayoutByIndex(PowerPoint.Presentation activePresentation, int customLayoutIndex)
{
activePresentation.Windows[1].ViewType = PpViewType.ppViewSlideMaster; //PpViewType.ppViewMasterThumbnails doesn't work for me for some reason
activePresentation.SlideMaster.CustomLayouts[customLayoutIndex].Select();
}
private static void SelectSlideMasterLayoutOfActiveSlide(PowerPoint.Application app)
{
var activeWindow = app.ActiveWindow;
var slideObj = activeWindow.View.Slide;
if (slideObj.GetType() == typeof(PowerPoint.Slide))
{
var slide = (PowerPoint.Slide)slideObj;
activeWindow.ViewType = PpViewType.ppViewSlideMaster; //PpViewType.ppViewMasterThumbnails doesn't work for me for some reason
slide.CustomLayout.Select();
}
}
}
}
Upvotes: 2