问题
I create a Powerpoint add-in and I need to find which slide is active in Slideshow Window. I have this code:
if (Globals.ThisAddIn.Application.SlideShowWindows.Count > 0)
{
for (int s = 0; s < Globals.ThisAddIn.Application.ActivePresentation.Slides.Count; s++)
{
//abc
}
}
So I check if slideshow window is running and then go through all slides in presentation. But this is not very good solution. I want to get current slide immediately.
回答1:
Here's the VBA to do what you want. It returns the index of the active slide in the first slideshow window:
SlideShowWindows(1).View.Slide.SlideIndex
回答2:
I tried this code .this is working for me..It may useful for new developers.
Microsoft.Office.Interop.PowerPoint.Presentation objPres;
Microsoft.Office.Interop.PowerPoint.SlideShowView oSlideShowView;
objPres = Globals.ThisAddIn.Application.ActivePresentation;
objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse;
PowerPoint.Slide curSlide_1 = ppApp.ActiveWindow.View.Slide;
objPres.SlideShowSettings.Run();
oSlideShowView = objPres.SlideShowWindow.View;
oSlideShowView.GotoSlide(curSlide_1.SlideIndex);
来源:https://stackoverflow.com/questions/23858619/how-to-find-current-slide-in-powerpoint-slideshow-window