View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default How to avoid selecting an object?


Does this macro do what you want?

Sub ShowText()
Dim R As Range
Dim OTbox As Object
Set R = Selection
For Each OTbox In ActiveSheet.Shapes
If OTbox.AutoShapeType = msoShapeRectangle Then
OTbox.Select
MsgBox Selection.Text
End If
Next OTbox
R.Select
End Sub

--
Rick (MVP - Excel)


"KB01" wrote in message
...
Below are two macros that were taken from an Excel VBA. They are
condensed to the minimum that still reproduces the problem. I need to
avoid selecting the object, but still need to read the text.
Can someone tell me why one macro works and the other does not?
Getting the AutoShapeType property (apparenty?) works. Why not getting
the text?
Is there a way to get the text from the rectangle object without
selecting it?

Thanks for any hints

KB

- - - - - - - - - -

Display text from all rectangles on a worksheet:

'This works, but selects the object which causes problems elsewhere,
e.g. if the worksheet is protected

Sub ShowText()
Dim OTbox As Object
For Each OTbox In ActiveSheet.Shapes
If OTbox.AutoShapeType = msoShapeRectangle Then
OTbox.Select
MsgBox Selection.Text
End If
Next OTbox
End Sub

'This returns an error 438 "Object does not support ..."

Sub ShowText()
Dim OTbox As Object
For Each OTbox In ActiveSheet.Shapes
If OTbox.AutoShapeType = msoShapeRectangle Then
MsgBox OTbox.Text
End If
Next OTbox
End Sub


*** Sent via Developersdex http://www.developersdex.com ***