PC Review


Reply
Thread Tools Rate Thread

How to avoid selecting an object?

 
 
KB01
Guest
Posts: n/a
 
      8th Jul 2009

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 With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      8th Jul 2009

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" <(E-Mail Removed)> wrote in message
news:OgAFxw5$(E-Mail Removed)...
> 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 With Quote
 
Mike H
Guest
Posts: n/a
 
      8th Jul 2009

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

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      8th Jul 2009
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" <(E-Mail Removed)> wrote in message
news:%23KxlvE6$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:OgAFxw5$(E-Mail Removed)...
>> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
PPT 2007: How can I avoid selecting the page number? =?Utf-8?B?bWxhaXJk?= Microsoft Powerpoint 6 18th May 2007 09:27 PM
How to avoid selecting column header row in DataGridView???? Hexman Microsoft Dot NET Framework Forms 2 24th Apr 2006 06:37 PM
Trying to Avoid Selecting Sheets Kevin O'Neill Microsoft Excel Programming 2 11th Nov 2005 08:55 PM
Treeview, avoid selecting node on keydown or up RB Smissaert Microsoft Excel Programming 0 4th Nov 2005 04:37 PM
how do i avoid crashing my ppt when selecting cont. loop? =?Utf-8?B?R2FyeQ==?= Microsoft Powerpoint 0 2nd Dec 2004 12:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:05 PM.