選択中のスライド、シェイプを取得する
using PowerPoint = Microsoft.Office.Interop.PowerPoint; public partial class ThisAddIn { PowerPoint.Selection GetSelection() { try { return this.Application.ActiveWindow.Selection; } catch (System.Runtime.InteropServices.COMException exc) { // TODO } return null; } PowerPoint.SlideRange GetSelectedSlideRange() { PowerPoint.Selection selection = GetSelection(); try { return (selection != null) ? selection.SlideRange : null; } catch (System.Runtime.InteropServices.COMException exc) { // TODO } return null; } PowerPoint.ShapeRange GetSelectedShapeRange() { PowerPoint.Selection selection = GetSelection(); try { return (selection != null) ? selection.ShapeRange : null; } catch (System.Runtime.InteropServices.COMException exc) { // TODO } return null; } public void Test() { PowerPoint.SlideRange selectedSlideRange = GetSelectedSlideRange(); PowerPoint.Slide firstSelectedSlide = selectedSlideRange[1]; PowerPoint.ShapeRange selectedShapeRange = GetSelectedShapeRange(); PowerPoint.Shape firstSelectedShape = selectedShapeRange[1]; } : }
スライドが選択されていない時にselection.SlideRangeを呼ぶとSystem.Runtime.InteropServices.COMExceptionが生じるようです。
同様に、シェイプが選択されていな時にselection.ShapeRangeを呼ぶと
System.Runtime.InteropServices.COMExceptionが生じるようです。
上図のようにスライド間にカーソルがあるときは、スライドは選択されていません。
得られたSlideRange, ShapeRangeのインデックスは1から始まります。