views:

747

answers:

3

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.

A: 

Would this link help?

Here's a synopsis:

Over the application, you have four choices:

  • xlDefault
  • xlWait
  • xlBeam
  • xlNorthwestArrow

You call it like:

Application.Cursor = xlDefault

Over forms, you have more choices. See the article for more.

Richard Morgan
Edited original question to clarify
Lunatik
A: 

I don't know what you mean with 'drawing mode'. However, if you want to change the appearance of your mouse cursor, the property you are looking for is Application.Cursor

You can set it to one of four predefined values: xlWait, xlNorthwestArrow, xlIBeam and xlDefault.

If you want to display other cursors, have a look this article on how to display a custom cursor in Access. Since it uses the WinAPI, the solution should work equally in Excel.

Edit:

In response to your edit: I don't think that it is possible to do what you want. The macro recorder doesn't pick it up because there is no VBA command that can do it. Depending and what you are trying to achieve by switching to design mode, there may be other ways though.

If you want to keep the user from changing the data in your workbook, you can hide the complete Excel window using the Application.Visible property.

If you want to keep the user from selecting or changinganything, but still display the data, have a look at ActiveSheet.Protect or ActiveWorkbook.Protect, available under Tools - Protection.

If you want to move or resize some controls in your workbook, you can do that programmatically by changing the Left, Top, Height and Width property of the control, you don't need to switch to design mode in order to do this from your macro.

Treb
My original thought was to pass control to the user to select one or more drawing objects, then have the next part of the code run on the selected shapes. I thought this would be more intuitive than selecting from a enumerated/named list in a control.I thought it was worth asking as, if it exists, it wouldn't be the first thing that the macro recorder doesn't pick up that is actually defined in the object model.
Lunatik
+2  A: 

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!

ewbi
Brilliant, had completely ignored using the commandbar!
Lunatik