Jamie Garroch (MVP)
asked on
Late binding not working as expected with PowerPoint MergeShapes method in VBA
Why does this not work when executed in Late Binding mode?
At the point the error is generated I examine the TypeName for oSel and get Selection so I don't understand why it's raising the mismatch error. If i change this line:
Option Explicit
#Const EarlyBinding = True
' To test in PowerPoint 2013 or later:
' 1. Add two shapes e.g. rectangles, to a slide and select them
' 2. Run Test with EarlyBinding set to True
' 3. Run Test with EarlyBinding set to False, which will generate a type mismatch error
Sub Test()
#If EarlyBinding Then
ActiveWindow.Selection.ShapeRange.MergeShapes msoMergeUnion
#Else
' Late Binding
Dim oSel As Object
Set oSel = ActiveWindow.Selection
oSel.ShapeRange.MergeShapes msoMergeUnion ' -> type mismatch error
#End If
End Sub
At the point the error is generated I examine the TypeName for oSel and get Selection so I don't understand why it's raising the mismatch error. If i change this line:
Dim oSel As Object
to this:Dim oSel As Selection
then it works as expected but I need it to work in late binding mode.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER