Updating OLE objects automatically using MS PowerPoint Add In

About updating OLE objects automatically

One of t he most frequent question s asked by the Aspose.Slides for C++ customers is how to create or change editable charts or any other OLE objects and have them automatically updated when opening the presentation. Unfortunately PowerPoint does not support any automatic macros, which are available in Excel and Word. The only ones available are the Auto_Open and Auto_Close macros. However, those only run automatically from an add-in. This short technical tip shows how to achieve that.

First, there are available several freeware add-ins that add the Auto_Open macro feature to PowerPoint for example AutoEvents Add-in and Event Generator .

After installing such Add-in, just add Auto_Open() macro (OnPresentationOpen() in case of “Event Generator”) to your template presentation as shown below:

Visual Basic




 Sub Auto_Open()

 Dim oShape As Shape

 Dim oSlide As Slide

 Dim oGraph As Object

 ' Loop through each slide in the presentation.

 For Each oSlide In ActivePresentation.Slides

     ' Loop through all the shapes on the current slide.

     For Each oShape In oSlide.Shapes

 	' Check whether the shape is an OLE object.

 	If oShape.Type = msoEmbeddedOLEObject Then

    	 		' 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 = Nothing

    		End If

     Next oShape

  Next oSlide

End Sub