S
sebastienm
Hi,
This one is driving me crazy
While i can change the displayed Text in a shape object, i cannot change it when the shape is grouped: Excel returns the error "Unable to ..." (it accept the property but cannot access it).
On the other hand, the methods to delete the text, access/change its font, or Fill color still work fine on that individual grouped shape.
I tried all the methods in the Sub bellow (assumes 2 shapes in activesheet, the second one has text, and they are grouped).
Any idea, pleeeeease?
'-------------------------------------
Sub ChangeRect2()
Dim s As Shape
Dim tf As TextFrame
Dim str As String
Set s = ActiveSheet.Shapes(1).GroupItems(2) 'shape 2
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
'--------------------------------------------------
One more thing: ungroup/regroup the shapes is not a good solution in my situation because i would have to do that hundreds of thousands of times.
This one is driving me crazy
While i can change the displayed Text in a shape object, i cannot change it when the shape is grouped: Excel returns the error "Unable to ..." (it accept the property but cannot access it).
On the other hand, the methods to delete the text, access/change its font, or Fill color still work fine on that individual grouped shape.
I tried all the methods in the Sub bellow (assumes 2 shapes in activesheet, the second one has text, and they are grouped).
Any idea, pleeeeease?
'-------------------------------------
Sub ChangeRect2()
Dim s As Shape
Dim tf As TextFrame
Dim str As String
Set s = ActiveSheet.Shapes(1).GroupItems(2) 'shape 2
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
'--------------------------------------------------
One more thing: ungroup/regroup the shapes is not a good solution in my situation because i would have to do that hundreds of thousands of times.