MS PowerPointアドインを使用してOLEオブジェクトを自動で更新する

OLEオブジェクトを自動で更新することについて

Aspose.Slidesの顧客からよく寄せられる質問の一つは、編集可能なグラフやその他のOLEオブジェクトを作成または変更し、プレゼンテーションを開いたときに自動的に更新されるようにする方法です。残念ながら、PowerPointはExcelやWordで利用可能な自動マクロをサポートしていません。利用可能なのはAuto_OpenおよびAuto_Closeマクロのみです。しかし、これらはアドインからのみ自動的に実行されます。この短い技術的ヒントでは、その方法を示します。

まず、Auto_Openマクロ機能をPowerPointに追加するいくつかのフリーウェアアドインがあります。たとえば、AutoEvents Add-inEvent Generatorです。

そのようなアドインをインストールした後、以下のようにテンプレートプレゼンテーションにAuto_Open()マクロ(「Event Generator」の場合はOnPresentationOpen())を追加します:

Shape oShape;
Slide oSlide;
// Loop through each slide in the presentation.
for (var oSlide : ActivePresentation.Slides) {
// Loop through all the shapes on the current slide.
for (var oShape : oSlide.Shapes) {
// Check whether the shape is an OLE object.
if ((oShape.Type == msoEmbeddedOLEObject)) {
// Found an OLE object; obtain object reference, and then update.
oObject = oShape.OLEFormat.Object;
oObject.Application.Update();
// Now, quit out of the OLE server program. This frees
// memory, and prevents any problems. Also, set oObject equal
// to Nothing to release the object.
oObject.Application.Quit();
oObject = null;
}
}
}