0
votes

Hello this is a follow up on this ticket: How to resolve Missing Powerpoint 15 Object Library Error

I developed a macro that exports something from excel to powerpoint in Excel 2010. I ran into issues when I tried to deploy to people with Office 2010. Per the advice of SO I changed the references to late binding to avoid version dependency. It is now possible to open and run the macro on office 2010 but users still see the error message: "Trouble loading DLL". It says missing 15 Powerpoint VBA when I click into the references. If I uncheck this and check 14 it will run, but it seems like someone in 2010 will have to do this each time they run the Macro. Any advice on how to proceed? I tried to add the following to resolve the issue

1: Code to repair refrences

Sub RemoveMissingReferences()
Dim Intrefcount As Integer

With ThisWorkbook.VBProject.references
    For Intrefcount = 1 To .Count
        If Left(.Item(Intrefcount).Description, 7) = "Missing" Then
             .Remove .Item(Intrefcount)
        End If
    Next Intrefcount
   End With
End Sub

2: Actual macro which exports from excel to PPT

Sub CopyDataToPPTBrandPers()
Const ppLayouttitleonly = 11
Const ppPasteEnhancedMetafile = 2

Dim objWorkSheet As Worksheet
Dim objRange As Range
Dim objPPT, objslide, objPresentation, shapePPTOne As Object
Dim intLocation, intHeight, inLayout, intRefCount As Integer
Dim strRange As String
Dim boolRefExists As Boolean

Application.ScreenUpdating = False

boolRefExists = False
With ThisWorkbook.VBProject.references
    For intRefCount = 1 To .Count
        If .Item(intRefCount).Description = _
            "Microsoft PowerPoint 14.0 Object Library" Then
            boolRefExists = True
        End If
    Next intRefCount
End With

Set objPPT = CreateObject("PowerPoint.Application")

objPPT.Visible = True
inLayout = 1
strRange = "p19:y48"  '<- here
intHeight = 430

Set objPresentation = objPPT.Presentations.Add
Set objslide = objPresentation.Slides.Add(1, inLayout)
objslide.Layout = ppLayouttitleonly

With objslide.Shapes.Title
    With .TextFrame.TextRange
        .Text = "Reebok - " & Sheets("Brand Personality").Cells(3, 2)
        .Words.Font.Bold = msoTrue
        .Font.Color = RGB(255, 255, 255)
    End With
    .Fill.Visible = msoTrue
    .Fill.Solid
    .Fill.ForeColor.RGB = RGB(192, 0, 0) '160, 157, 117)
    .Height = 50
End With

Set objRange = Sheets("Brand Personality").Range(strRange)
objRange.Copy

Set shapePPTOne = objslide.Shapes.PasteSpecial(DataType:=ppPasteEnhancedMetafile, _
    Link:=msoFalse)
DoEvents

If boolRefExists = True Then
    shapePPTOne.Left = 100
    shapePPTOne.Top = 100
    shapePPTOne.Height = intHeight    
Else
    shapePPTOne(1).Left = 220
    shapePPTOne(1).Top = 100
    shapePPTOne(1).Height = intHeight
End If

Set shapePPTOne = Nothing
'Set shapePPTTwo = Nothing
Set objRange = Nothing
Set objPPT = Nothing
Set objPresentation = Nothing
Set objslide = Nothing

Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox "Update Complete"

End Sub
1
Note the #1 Code to repair references was timing out on the left command. I couldn't figure out why - Edward Armstrong
If you already migrated to Late Bind then just remove any Reference and save the .xlsm file. Late Binding doesn't need any reference at all. Also msoTrue and msoFalse are PPt variables, so need to change it to -1 and 0 respectively. Then try to scan again your code, I could've missed other variables. - L42
Your declarations are not doing what you might expect: Dim objPPT, objslide, objPresentation, shapePPTOne As Object creates shapePPTOne as an Object variable, the rest as Variants. Likewise: Dim intLocation, intHeight, inLayout, intRefCount As Integer gives you intRefCount as an Integer, the rest are Variants. In this case it probably doesn't matter much, but can sometimes lead to obscure errors and strange results. Best to declare the vars properly. - Steve Rindsberg

1 Answers

2
votes

Try this snippet instead to simplify things:

' PasteSpecial returns a shaperange consisting of 1 shape, so add a (1) at the end to 
' set shapePPTOne equal to the first shape in the range:
Set shapePPTOne = objslide.Shapes.PasteSpecial(DataType:=ppPasteEnhancedMetafile, _
    Link:=msoFalse)(1)
DoEvents

Then you don't need all this stuff, just shapePPTOne.Left = xxx etc.
'If boolRefExists = True Then
    shapePPTOne.Left = 100
    shapePPTOne.Top = 100
    shapePPTOne.Height = intHeight    
'Else
'    shapePPTOne(1).Left = 220
'    shapePPTOne(1).Top = 100
'    shapePPTOne(1).Height = intHeight
'End If

IIRC, msoTrue and msoFalse are Office vars, not PPT-specific, so you probably don't need to change them. Or you can simply use True and False.

And if you've removed the reference to PPT, there's no point in checking the project to see if the reference is there; it won't be. And if you leave the reference, users will always see the message complaining about the missing reference when they're not running the 2010 version of Office.