Link to home
Start Free TrialLog in
Avatar of Jamie Garroch (MVP)
Jamie Garroch (MVP)Flag for United Kingdom of Great Britain and Northern Ireland

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?

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

Open in new window


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

Open in new window

to this:
Dim oSel As Selection

Open in new window

then it works as expected but I need it to work in late binding mode.
ASKER CERTIFIED SOLUTION
Avatar of John Wilson
John Wilson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jamie Garroch (MVP)

ASKER

"looks like a VBA bug" would have been sufficient to answer the question but no, I got a bonus workaround too! Thank you JSRWilson. I thought I was going mad yesterday staring at just half a dozen lines of code whilst scratching my head!