1

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

Gaffi
  • 4,307
  • 8
  • 43
  • 73
ashwell
  • 224
  • 2
  • 13

1 Answers1

2

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.

joeschwa
  • 3,083
  • 1
  • 21
  • 41
  • This is perfect, thank you! Exactly what I needed. I do notice that the macros are stored in each presentation, is there a way to bind the macro to PowerPoint instead of each presentation? – ashwell Oct 25 '11 at 01:45
  • 1
    Yes. You can store the macro in a PowerPoint macro-enabled template file (.potm) and then place the file in the trusted default location for PowerPoint templates. Any time this file is accessed via File|New|My Templates it will copy it's contents into a new PowerPoint presentation. If you name the file blank.potm (not blank.potx, which should not be concurrently present) this will become the default presentation template and copy itself into all new Blank presentations. (Either approach should display the QAT button associated with the template when new presentations are created.) – joeschwa Oct 25 '11 at 15:30
  • AMAZING! Works perfect, my professor is very pleased thank you very much for your help. I look much better with hair, and if I had tried to figure this out my self I probably would have pulled it all out by now...thanks again! – ashwell Nov 04 '11 at 18:37
  • I have selected a slide before running the macro but still I'm getting error "Method AddOLEobject of object 'Shapes' failed". – harishli2020 Dec 06 '21 at 01:58
  • @harishli2020 please post a new question showing your code. – joeschwa Dec 06 '21 at 02:24