View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
MM User MM User is offline
external usenet poster
 
Posts: 27
Default Prompt user to select a shape

Thanks Dave and Gary,

Both options are suitable and I will probably use a bit of both - thanks!



"Dave Peterson" wrote in message
...
Maybe you could show a dialog that allows the user to choose a shape (or
multiple shapes).

In xl2003, there is an icon that you can add to your favorite toolbar.

You can do it via:
tools|customize|commands tab|drawing category
look for "Select multiple objects"

In code, you can do this:

Option Explicit
Sub testme01()
Dim myCtrl As CommandBarControl
Dim myCB As CommandBar
Dim iCtr As Long

Set myCB = Nothing

Set myCtrl = Nothing
On Error Resume Next
Set myCtrl = Application.CommandBars.FindControl(ID:=3990)
On Error GoTo 0

If myCtrl Is Nothing Then
'not on any existing toolbar, so create a temporary toolbar
Set myCB = Application.CommandBars.Add(temporary:=True)
myCB.Visible = False
'add that button
Set myCtrl = myCB.Controls.Add(Type:=msoControlButton, ID:=3990)
End If

myCtrl.Execute
MsgBox TypeName(Selection)

Select Case LCase(TypeName(Selection))
Case Is = LCase("Range")
MsgBox "A range is selected"
Case Else
For iCtr = 1 To Selection.ShapeRange.Count
MsgBox Selection.ShapeRange(iCtr).Name
Next iCtr
End Select

'clean up
If myCB Is Nothing Then
'found it on an existing toolbar
Else
myCB.Delete
End If

End Sub

=========
Personally, I think I'd tell the users to select the object before the
code
starts. You can test the typename() of the selection to see if they have
a
Range selected.

If it is a Range, just yell at the user to select an object and start the
macro
once more.


MM User wrote:

Hi,

You can use the InputBox to prompt the user to enter some text or range -
is
it possible to also prompt the user to select a shape?

Thanks


--

Dave Peterson