如何在PowerPoint中第一张幻灯片之前和之后添加自定义幻灯片

时间:2014-07-09 10:33:45

标签: c# vsto powerpoint add-in

我创建了一个Office加载项,我需要在单击自定义按钮时向演示文稿添加幻灯片。

现在,如果用户在幻灯片预览窗格(即左侧窗格)中单击顶部(第一张幻灯片之前),则应在第一个位置添加新的自定义幻灯片。但是,如果用户在任意两张幻灯片之间进行选择,则应在其间添加新的自定义幻灯片。

我正在尝试以下代码:

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);
}

但是,我基本上无法弄清楚如何区分鼠标在顶部和两张幻灯片之间的点击时间。

请参阅随附的图片和帮助。Shows the cursor positions) 谢谢!

1 个答案:

答案 0 :(得分:1)

更改视图然后更改回来。如果光标位于幻灯片2和3之间,当您返回原始视图时,它将位于2。

例如,在VBA中你会:

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

似乎有效的另一个技巧(仅当你处于普通视图时):

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

问题:如果光标位于第一张幻灯片之前或幻灯片1和2之间,则两种方法都将选择第一张幻灯片。这将使得很难判断光标是在幻灯片1和2之间还是在幻灯片1之前。

除了将箭头键发送到窗口之外,我不知道如何解决这个问题。难看。

相关问题