Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to avoid selecting an object?


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 ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
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 ***


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How to avoid selecting an object?


Hi,

Try it like this

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

Mike

"KB01" wrote:

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 ***

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to avoid selecting an object?

Actually, use this macro instead (it is your second macro modified to
work)...

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

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
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 ***



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting last pasted object avi Excel Programming 1 April 21st 07 10:23 PM
Selecting Drawing Object By Name Zone Excel Programming 3 December 22nd 06 08:21 PM
Trying to Avoid Selecting Sheets Kevin O'Neill[_2_] Excel Programming 2 November 11th 05 08:55 PM
Treeview, avoid selecting node on keydown or up RB Smissaert Excel Programming 0 November 4th 05 04:37 PM
Selecting object Ronbo Excel Programming 2 January 13th 05 12:06 PM


All times are GMT +1. The time now is 02:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"