0
votes

I have created an Office add-in in which I need to add a slide to the presentation on click of a custom button.

Now, if the user clicks at the top(before first slide) in slide preview pane(i.e pane in the left hand side), the new custom slide should be added at the first position. If however, the user selects in between any two slides, the new custom slide should be added in between.

I am trying the below code:

if (insertNextSlideHere == 0)
{
                slide = Globals.ThisAddIn.Application.ActivePresentation.Slides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank);
}
else if (Globals.ThisAddIn.sldIndexVal == 0 && Globals.ThisAddIn.Application.ActivePresentation.Windows[1].Selection.SlideRange[1].SlideIndex == 1)
{
                slide = Globals.ThisAddIn.Application.ActivePresentation.Slides.Add(Globals.ThisAddIn.Application.ActivePresentation.Windows[1].Selection.SlideRange[1].SlideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank);
slide.MoveTo(1);
}
else if (Globals.ThisAddIn.sldIndexVal == 0 && Globals.ThisAddIn.Application.ActivePresentation.Windows[1].Selection.SlideRange[1].SlideIndex > 1)
{
MessageBox.Show("loop1");
slide = Globals.ThisAddIn.Application.ActivePresentation.Slides.Add(Globals.ThisAddIn.Application.ActivePresentation.Windows[1].Selection.SlideRange[1].SlideIndex + 1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank);                    

}
else if (Globals.ThisAddIn.sldIndexVal == 0)
{
MessageBox.Show("loop2");
slide = Globals.ThisAddIn.Application.ActivePresentation.Slides.Add(Globals.ThisAddIn.Application.ActivePresentation.Windows[1].Selection.SlideRange[1].SlideIndex, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank);
slide.MoveTo(2);

}
else
{
MessageBox.Show("loop3");
slide = Globals.ThisAddIn.Application.ActivePresentation.Slides.Add(Globals.ThisAddIn.Application.ActivePresentation.Windows[1].Selection.SlideRange[1].SlideIndex +1, 
Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank);
}

However, I am basically not able to figure out how to distinguish between when the mouse is clicked at the top and when in between two slides.

Please refer to the image attached and help.Shows the cursor positions) Thanks!

1

1 Answers

1
votes

Change the view then change back. If the cursor was between, say, slides 2 and 3, when you return to the original view, it'll be on 2.

For example, in VBA you'd:

Dim lCurrentView As Long
' save the current view 
lCurrentView = ActiveWindow.ViewType
' switch views
ActiveWindow.ViewType = ppViewNotesPage
' switch back
ActiveWindow.ViewType = lCurrentView
' and now add a slide after the current slide

Another trick that seems to work (only if you're in Normal view):

For x = 1 To ActiveWindow.Panes.Count
    Debug.Print ActiveWindow.Panes(x).ViewType
    ActiveWindow.Panes(x).Activate
Next

Problem: if the cursor is sitting before the first slide or between slides 1 and 2, both methods will select the first slide. That will make it difficult to tell whether the cursor was between slides 1 and 2 or before slide 1.

I'm not sure how to solve that one, other than maybe by sending arrowkeys to the window. Ugly.