0
votes

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
you should add your code in the question0m3r
Welcome to Stack Overflow! I've cleaned up the wording of your post to make it clearer. I believe you would like to change your code to rely on late binding rather than early binding. Is that correct? While it seems you have received helpful answers, you should be aware that posting your code is good practice when asking questions here. You can always edit your question to include your code or additional information.Excellll

2 Answers

1
votes

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

0
votes

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"