excelvbacoreldraw

What is causing this CorelDraw VBA Macro Mismatch Error?


I have a short Excel VBA macro that takes the current selection in an (open) CorelDraw drawing and moves it. Why am I getting a mismatch runtime error when I set OrigSelection to be the app.ActiveSelectionRange? Here is my code:

Private Sub MoveAndResizeSelection()
    Dim app As CorelDraw.Application
    Set app = CorelDraw.Application
    Dim OrigSelection As ShapeRange
    Set OrigSelection = app.ActiveSelectionRange
    
    'Move and Resize the selection
    OrigSelection.Move 2.595, -6.751
    
End Sub

I am using Excel Office 16 and CorelDraw Graphics Suite 2022.


Solution

  • The culprit is

    Dim OrigSelection As ShapeRange
    

    which is implicitly

    Dim OrigSelection As Excel.ShapeRange
    

    Change to

    Dim OrigSelection As CorelDraw.ShapeRange