Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default loop through rectangles on worksheet

Hello,

I am working on extracting data out of an OLE object pasted into Excel.
After pasting the object into excel I perform an 'ungroup' on it and it is
converted into a collection of shape (or rectangle) objects with text in them.
I am trying to loop through each of these rectangles sequentially and grab
the text out of them. The problem is that I do not know what the names of
the rectangles will be. I could have "Rectangle 1", "Rectangle 2", and
"Rectangle 3." I could have "Rectangle 225" through "Rectangle 467," or any
sequence of rectangles. Regardless, I want to start with the lowest numbered
rectangle and loop until i'm out of rectangles.

The code I have so far will only work if I know the beginning and ending
rectangle names. In this case I loop through "Rectangle 5" through
"Rectangle 10"

Dim FirstRect, LastRect as Integer
FirstRect = 5
LastRect = 10

For Index = FirstRect To LastRect
ThisRectangle = "rectangle" & " " & Index
msgbox = Worksheets("sheet1").Shapes(ThisRectangle).TextFra me.
Characters.Text
Next Index


How can I change this code to loop sequentially through all rectangles on the
worksheet, no matter what the starting and ending rectangle numbers are?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200606/1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default loop through rectangles on worksheet

Hi jeichhold,

Something like this should do the trick:

Sub test()
Dim objRect As Object
Dim sText As String

For Each objRect In Sheets("Sheet1").Rectangles
sText = vbNullString
On Error Resume Next
If Not objRect.Text Is Nothing Then
sText = objRect.Text
End If
On Error GoTo 0
Debug.Print objRect.Name & ": " & sText
Next objRect
End Sub

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

jeichhold via OfficeKB.com wrote:
Hello,

I am working on extracting data out of an OLE object pasted into
Excel.
After pasting the object into excel I perform an 'ungroup' on it and
it is converted into a collection of shape (or rectangle) objects
with text in them. I am trying to loop through each of these
rectangles sequentially and grab the text out of them. The problem
is that I do not know what the names of the rectangles will be. I
could have "Rectangle 1", "Rectangle 2", and "Rectangle 3." I could
have "Rectangle 225" through "Rectangle 467," or any sequence of
rectangles. Regardless, I want to start with the lowest numbered
rectangle and loop until i'm out of rectangles.

The code I have so far will only work if I know the beginning and
ending rectangle names. In this case I loop through "Rectangle 5"
through "Rectangle 10"

Dim FirstRect, LastRect as Integer
FirstRect = 5
LastRect = 10

For Index = FirstRect To LastRect
ThisRectangle = "rectangle" & " " & Index
msgbox =
Worksheets("sheet1").Shapes(ThisRectangle).TextFra me. Characters.Text
Next Index


How can I change this code to loop sequentially through all
rectangles on the worksheet, no matter what the starting and ending
rectangle numbers are?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default loop through rectangles on worksheet

One way

Dim oRect As Object

For Each oRect In ActiveSheet.Rectangles
On Error Resume Next
MsgBox oRect.Text
On Error GoTo 0
Next oRect


--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"jeichhold via OfficeKB.com" <u3773@uwe wrote in message
news:625c722ac084e@uwe...
Hello,

I am working on extracting data out of an OLE object pasted into Excel.
After pasting the object into excel I perform an 'ungroup' on it and it is
converted into a collection of shape (or rectangle) objects with text in

them.
I am trying to loop through each of these rectangles sequentially and grab
the text out of them. The problem is that I do not know what the names of
the rectangles will be. I could have "Rectangle 1", "Rectangle 2", and
"Rectangle 3." I could have "Rectangle 225" through "Rectangle 467," or

any
sequence of rectangles. Regardless, I want to start with the lowest

numbered
rectangle and loop until i'm out of rectangles.

The code I have so far will only work if I know the beginning and ending
rectangle names. In this case I loop through "Rectangle 5" through
"Rectangle 10"

Dim FirstRect, LastRect as Integer
FirstRect = 5
LastRect = 10

For Index = FirstRect To LastRect
ThisRectangle = "rectangle" & " " & Index
msgbox =

Worksheets("sheet1").Shapes(ThisRectangle).TextFra me.
Characters.Text
Next Index


How can I change this code to loop sequentially through all rectangles on

the
worksheet, no matter what the starting and ending rectangle numbers are?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200606/1



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default loop through rectangles on worksheet

Ok, great. I think this will do the trick. thanks

Bob Phillips wrote:
One way

Dim oRect As Object

For Each oRect In ActiveSheet.Rectangles
On Error Resume Next
MsgBox oRect.Text
On Error GoTo 0
Next oRect

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

Hello,

[quoted text clipped - 24 lines]
How can I change this code to loop sequentially through all rectangles on the
worksheet, no matter what the starting and ending rectangle numbers are?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200606/1
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
Clearing rectangles Andrew B[_5_] Excel Programming 1 April 6th 06 12:46 AM
Worksheet loop won't loop L. Howard Kittle Excel Programming 4 March 17th 06 12:56 AM
How to insert small colored dots or rectangles in cells of excel George A. Yorks Excel Discussion (Misc queries) 1 February 2nd 05 07:07 PM
worksheet loop scott[_8_] Excel Programming 8 November 17th 03 09:49 PM
How? Macro to copy range to new worksheet, name new worksheet, loop Repoman Excel Programming 9 October 9th 03 01:45 PM


All times are GMT +1. The time now is 06:48 PM.

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

About Us

"It's about Microsoft Excel"