Macro - Select shape with Pick tool after creating

Hi Folks,

Can anyone help me write a macro to select a rectangle shape with the pick tool after I manually create it?  Normally, when you're done creating a rectangle, the rectangle tool remains selected.  I'd like it to automatically return to the Pick tool (with the newly created object selected) after manually creating a rectangle.

Thanks very much,

Jack

Parents Reply
  • I've written a few scripts in the past, but this one is eluding me.

    This one is more involved, to the extent that you are not just trying to create or modify CorelDRAW content using a macro. Instead, you're trying to have CorelDRAW always watching to see if a Rectangle has been created, and THEN trying to do something using a macro (change the active tool).

    You could try putting this code in the ThisMacroStorage section of a VBA project:

    Dim WithEvents CurDoc As Document
    
    Private Sub GlobalMacroStorage_WindowActivate(ByVal Doc As Document, ByVal Window As Window)
        Set CurDoc = Doc
    End Sub
    
    Private Sub GlobalMacroStorage_WindowDeactivate(ByVal Doc As Document, ByVal Window As Window)
        Set CurDoc = Nothing
    End Sub
    
    Private Sub CurDoc_ShapeCreate(ByVal Shape As Shape)
    
        If ActiveShape.Type = cdrRectangleShape Then
            Application.ActiveTool = cdrToolPick
        End If
    End Sub
    

    Code that runs automatically based on events should be used with caution!

    In that example, I limited it to only Rectangle shapes, but that could be changed to include other specific types of shapes. Or, you could have it NOT apply to only specific types of shapes. Or, you could have it apply to all types of shapes (perform no check at all with respect to shape type).

Children