I'm trying to create AHK script for merging shapes in PowerPoint
This VBA macro works fine, it takes selected shapes and combine them:
Sub mergeShapes()
ActiveWindow.Selection.ShapeRange.mergeShapes msoMergeCombine
End Sub
But when I put the script into AHK, the call raises Type mismatch error:
^!m::
WinActivate, ahk_class screenClass ahk_exe POWERPNT.EXE
msoMergeCombine:=2
ppt := ComObjActive("PowerPoint.Application")
ppt.ActiveWindow.Selection.ShapeRange.MergeShapes(msoMergeCombine)
Return
Error: 0x80020005 - Type mismatch.
Specifically: MergeShapes
I put the code into PowerShell to identify what could go wrong, and found out that it won't work either:
$app = New-Object -ComObject powerpoint.application
$sr = $application.ActiveWindow.Selection.ShapeRange
$sr.MergeShapes(2)
and got error message:
Exception setting "MergeShapes": Cannot convert the "2" value of type "int" to type "Object".
At line:1 char:1
+ $sr.MergeShapes(2)
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : RuntimeException
OK, it seems that the first argument must be of an Object type, so I create an object and pass it to the method to see what happens. It gets worse:
$obj = New-Object Object
$sr.MergeShapes($obj)
Exception setting "MergeShapes": Cannot convert the "System.Object" value of type "Object" to type "Object".
It seems that the method MergeShapes is somehow declared, but I couldn't see it in the list of methods when I call:
$sr | Get-Member -MemberType Method
Please suggest how I can troubleshoot this.