Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Changing Text in grouped shapes

Hi,
I have a problem modifying the text in some shapes that are grouped. I encounter no difficulty doing that on non-grouped shapes.
Run the code bellow in a new sheet:
-Sub Add2Rectangles: creates 2 rectangle shapes and set the text for the second one.
-Sub GroupThem: group the two shapes into one group
-Sub ChangeRect2():
- set the font for the 2nd box to strikethrough <-- works
- delete some of the characters of 2nd shape <-- works
- then it try to modify the text of 2nd shape using several methods <-- all FAILS

Now, delete the shapes on the sheet and create a single shape in which you add some text. In ChangeRect2, replace the line:
Set s = ActiveSheet.Shapes(1).GroupItems(2)
by
Set s = ActiveSheet.Shapes(1)
Finally run just ChangeRect2, the code runs perfectly well.

Anybody has an idea?
Thanks
Sebastien

'-------------------------------------------------------
Sub Add2Rectangles()
With ActiveSheet
.Shapes.AddShape msoShapeRectangle, 97.5, 75.75, 76.5, 49.5
.Shapes.AddShape msoShapeRectangle, 119.25, 88.5, 32.25, 14.25
.Shapes(2).TextFrame.Characters.Text = "Ungroup"
End With
End Sub

Sub GroupThem()
Dim sr As ShapeRange
With ActiveSheet
.Shapes.Range(Array(.Shapes(1).Name, .Shapes(2).Name)).Group
End With
End Sub

Sub ChangeRect2()
Dim s As Shape
Dim tf As TextFrame
Dim str As String

Set s = ActiveSheet.Shapes(1).GroupItems(2) 'ActiveSheet.Shapes(1)
Set tf = s.TextFrame

With tf
str = .Characters().Text

'-------WORKS FINE------------------
'Set strikethrough
.Characters().Font.Strikethrough = True
'Delete portion of the text
.Characters(1, 2).Delete

'------- FAILS -----------------
'Inserting characters
.Characters(1).Insert "hihihi"
.Characters(1, 2).Insert "hi"
'Changing the text directly
.Characters.Text = "HHHH"
.Characters(1, 2).Text = "HH"
'Chanhing the text through the OLEObject
s.OLEFormat.Object.Text = "aaa"
s.OLEFormat.Object.Caption = "aaa"

MsgBox s.Name & " = " & TypeName(s.OLEFormat.Object)
End With
End Sub
'--------------------------------------------------
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Changing Text in grouped shapes

Hi Sebastien,

This has bitten me. Haven't looked recently but searching
a while back suggested the only way to change text (ie
characters, not format) in individual Groupitems is to
ungroup and regroup. I found this hard to accept, went
round in circles before conceding defeat.

One point to bear in mind, if you have a treelike
structure of sub-groups you may need a recursive routine
to ungroup until you find your object. Then similar in
reverse if necessary.

If you find a solution avoiding ungroup / regroup pls post
back.

Regards,
Peter

-----Original Message-----
Hi,
I have a problem modifying the text in some shapes that

are grouped. I encounter no difficulty doing that on non-
grouped shapes.
Run the code bellow in a new sheet:
-Sub Add2Rectangles: creates 2 rectangle shapes and set

the text for the second one.
-Sub GroupThem: group the two shapes into one group
-Sub ChangeRect2():
- set the font for the 2nd box to strikethrough <--

works
- delete some of the characters of 2nd shape <-- works
- then it try to modify the text of 2nd shape using

several methods <-- all FAILS

Now, delete the shapes on the sheet and create a single

shape in which you add some text. In ChangeRect2, replace
the line:
Set s = ActiveSheet.Shapes(1).GroupItems(2)
by
Set s = ActiveSheet.Shapes(1)
Finally run just ChangeRect2, the code runs perfectly

well.

Anybody has an idea?
Thanks
Sebastien

'-------------------------------------------------------
Sub Add2Rectangles()
With ActiveSheet
.Shapes.AddShape msoShapeRectangle, 97.5, 75.75,

76.5, 49.5
.Shapes.AddShape msoShapeRectangle, 119.25, 88.5,

32.25, 14.25
.Shapes(2).TextFrame.Characters.Text = "Ungroup"
End With
End Sub

Sub GroupThem()
Dim sr As ShapeRange
With ActiveSheet
.Shapes.Range(Array(.Shapes(1).Name, .Shapes

(2).Name)).Group
End With
End Sub

Sub ChangeRect2()
Dim s As Shape
Dim tf As TextFrame
Dim str As String

Set s = ActiveSheet.Shapes(1).GroupItems

(2) 'ActiveSheet.Shapes(1)
Set tf = s.TextFrame

With tf
str = .Characters().Text

'-------WORKS FINE------------------
'Set strikethrough
.Characters().Font.Strikethrough = True
'Delete portion of the text
.Characters(1, 2).Delete

'------- FAILS -----------------
'Inserting characters
.Characters(1).Insert "hihihi"
.Characters(1, 2).Insert "hi"
'Changing the text directly
.Characters.Text = "HHHH"
.Characters(1, 2).Text = "HH"
'Chanhing the text through the OLEObject
s.OLEFormat.Object.Text = "aaa"
s.OLEFormat.Object.Caption = "aaa"

MsgBox s.Name & " = " & TypeName(s.OLEFormat.Object)
End With
End Sub
'--------------------------------------------------
.

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
Changing position of shapes in chart Matt S[_2_] Excel Discussion (Misc queries) 1 March 25th 10 12:14 PM
Grouped Items won't Stay Grouped When Moving Object Heather02 Excel Discussion (Misc queries) 0 February 12th 09 07:08 PM
changing the depth of 3d shapes Zagrijs Venter[_2_] Charts and Charting in Excel 0 July 28th 08 08:48 AM
How can I loop to find the grouped shapes count David Cuthill Excel Programming 3 January 26th 04 08:22 PM
Text on shapes Jay[_11_] Excel Programming 0 September 5th 03 08:00 AM


All times are GMT +1. The time now is 07:22 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"