Search code examples
vbaexcelcursor

Programmatically set "Select objects" cursor in Excel


I'm struggling to find out how to programmatically enable the "Select objects" cursor type. I checked the object browser and expected to find a property like Application.CursorType or Application.DrawingMode.

Changing the cursor type isn't picked up in the macro recorder and I must be searching for the wrong terms as I can't find information about this anywhere.

Edit: I should've made it clear I'm not talking about the cursor appearance that can be set via Application.Cursor. Rather, I want to set the cursor into the same mode as can be set via the GUI by clicking the "Select objects" icon on the Drawing toolbar. This is the cursor that only allows selection of shapes and ignores cells, text and the formula bar.

Actually, I never knew the correct name for this cursor mode until I checked the tooltip to write this update, perhaps that'll help.


Solution

  • I don't quite follow why you want to do this, but you can toggle the "Select Objects" drawing mode programmatically by executing the built-in CommandBar control:

    Call CommandBars("Drawing").Controls("Select Objects").Execute
    

    And you can determine the current mode by checking its state:

    If CommandBars("Drawing").Controls("Select Objects").State Then
      Call Debug.Print("Select Object mode is on")
    End If
    

    Good luck!