Search code examples
vbapowerpointpowerpoint-2007

Create new Equation Macro in PowerPoint 2007


I'm helping out one of my professors but what should be a simple task is starting to frustrate me.

I do not have any experience with Visual Basic used to create macros in MS Office 2007, specifically PowerPoint '07.

All I need is a macro for inserting a new equation into a PowerPoint slide, the macro will then be used as a button on the quick access toolbar. The macro should preform these two tasks:

1) On the Insert menu, click Object.

2) In the Object type list, click Microsoft Equation 3.0.

(taken from http://office.microsoft.com/en-us/powerpoint-help/insert-an-equation-HP005194680.aspx ~I know it "applies" to 2003 but it is the same process in 2007)

I'm really sorry to be asking such a simple question here but I have been all over the net looking for help and can't find a simple reference of the VB Library that I can understand. From what I do understand I need to navigate down through the objects PowerPoint, Presentation, Slide, and then add a Shape? Or maybe it can be done through the CommandBars object? I feel like this is a really simple problem that can solved by one of you knowledgeable fellows to save me from several more hours of Google searches that get me no where....

Basically the end result would be a button on the quick access toolbar that would open the Equation Editor 3.0


Solution

  • Microsoft Equation 3.0 creates an OLE Object, which can be created and opened with this code:

    Dim SlideNumber As Integer
    Dim ShapesCount As Integer
    
    SlideNumber = ActiveWindow.View.Slide.SlideIndex
    With ActivePresentation.Slides(SlideNumber)
        .Shapes.AddOLEObject Left:=100, Top:=100, Width:=200, Height:=100, ClassName:="Equation.3", DisplayAsIcon:=False
        ShapesCount = .Shapes.Count
        .Shapes(ShapesCount).OLEFormat.Activate
    End With
    

    It's worth noting that the code above needs a slide to be selected to work. If no slide is selected, it will throw an error. You may wish to add additional code to avoid such complications.

    Hope this helps.