Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set "Select objects" cursor in Excel

Tags:

cursor

excel

vba

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.

like image 215
Lunatik Avatar asked Dec 13 '25 04:12

Lunatik


2 Answers

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!

like image 110
ewbi Avatar answered Dec 14 '25 20:12

ewbi


I'm a little 'late to the party' on this one but here is the answer to 'why he wants to do this' as well as 'what he wants to do'.

'Turn ON 'Select Objects' option during initial display. While ON, cell input is prevented.
If CommandBars("Drawing").Controls("Select Objects").State = False Then
    CommandBars("Drawing").Controls("Select Objects").Execute
End If

I use this in a simple timer application which has one command button and two check boxes on the 'ActiveSheet' display. By turning ON 'Select Objects', I limit the cursor input targets to these three items. Cells cannot be selected.

Cheers, Lawrence

like image 21
Lawrence Baker Avatar answered Dec 14 '25 20:12

Lawrence Baker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!