我正在使用Coded UI和VSTO自动化PowerPoint场景。在我的PowerPoint演示文稿中,我已经创建了一个“操作”设置,在形状上启动记事本。在幻灯片放映期间,我需要通过单击“文本/形状”来调用此操作,以便它将打开notepad.exe。有谁能帮我实现这个功能?我编写了以下代码。
//To launch Powepoint
PowerPoint.Application objPPT = new PowerPoint.Application();
objPPT.Visible = Office.MsoTriState.msoTrue;
//Add new presentation
PowerPoint.Presentations oPresSet = objPPT.Presentations;
PowerPoint.Presentation oPres = oPresSet.Add(Office.MsoTriState.msoTrue);
//Add a slide
PowerPoint.Slides oSlides = oPres.Slides;
PowerPoint.Slide oSlide = oSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
//Add text
PowerPoint.TextRange tr = oSlide.Shapes[1].TextFrame.TextRange;
tr.Text = "Launch notepad";
tr.Select();
//Add Action settings on the shape
oSlide.Shapes[1].ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Action = PowerPoint.PpActionType.ppActionRunProgram;
oSlide.Shapes[1].ActionSettings[PowerPoint.PpMouseActivation.ppMouseClick].Run = "c:\\windows\\notepad.exe";
//start slideshow
objPPT.ActivePresentation.SlideShowSettings.Run();
这将启动演示文稿的幻灯片,并显示第一张幻灯片“在形状上定义操作设置”。现在我该如何通过API自动启动notepad.exe?不幸的是,编码UI无法检测幻灯片中的对象。因此,UI鼠标单击选项可能不可行。
[编辑] 已经取得了在幻灯片放映期间获取形状对象的一点进展。这是以上代码的扩展部分。
PowerPoint.SlideShowWindow oSsWnd = objPPT.ActivePresentation.SlideShowWindow;
PowerPoint.Shape oShape = oSsWnd.View.Slide.Shapes[1];
Shell(ActionSettings[Click].Run)
,如果 Action = ppActionRunProgram。 - Paul B.