Code using PowerPoint Object Library 15.0 does not work on machines with library 14.0

2.5k views Asked by At

I have a VBA macro that creates a PPT deck from rows in Excel. It works great on my PC (with PowerPoint Object Library 15.0), but when I distribute to people with an older PowerPoint Object Library (e.g., 14.0), it hoses the format of pasted shapes.

I read about the Early/Late binding and do not know how to address the problem. How do I change my code to use early binding rather than late binding? Other related questions I've found did not have answers.

2

There are 2 answers

0
ChipsLetten On

To use Late Binding, in the VBA IDE, go into Tools -> References and uncheck the Powerpoint entry. This will remove all knowledge of the Powerpoint object model and constants from the compiler. You will need to change any Dim statements that mention a Powerpoint object to simply Object, for example:

Dim mySlide As Slide

to

Dim mySlide As Object

If you use any constants, such as msoTextOrientationHorizontal in this code:

    ActivePresentation.Slides(1).Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
    Left:=100, Top:=100, Width:=200, Height:=50).TextFrame _
    .TextRange.Text = "Test Box"

you will need to replace the constant with the numeric value.

    ActivePresentation.Slides(1).Shapes.AddTextbox(Orientation:=1, _
    Left:=100, Top:=100, Width:=200, Height:=50).TextFrame _
    .TextRange.Text = "Test Box"
0
vacip On

Write your code using early binding, it is easier that way. Once you are finished, change it to late binding.

Early binding: Check the reference (Tools-->References) to the Ms PowerPoint 15.0 Object Library.

Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As PowerPoint.Slide

Set pptApp = CreateObject("Powerpoint.Application")
Set pptPres = pptApp.Presentations.Add
Set pptSlide = pptPres.Slides.Add(1, ppLayoutTwoObjects)

Late binding: Remove the reference to the PP15 Object Library.

Dim pptApp As Object
Dim pptPres As Object
Dim pptSlide As Object

Set pptApp = CreateObject("Powerpoint.Application")
Set pptPres = pptApp.Presentations.Add
Set pptSlide  = pptPres.Slides.Add(1, 29)

Note that in late binding, you can't use the built-in constants, eg. ppLayoutTwoObjects. You will have to use their numerical value.

You can read more on early VS late binding here: http://word.mvps.org/faqs/interdev/EarlyvsLateBinding.htm