How to change Text

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.
 
C

Calligra

I'm not for sure, but I think your problem is that you're not specifying
which object in the group to access.

Try below:

dim s as oleobject

for i = 1 to ???
set s = sheet1.oleobjects("TypeOfObject" & i) ' Where the type of object
is the name of your shape

if s.name = blah then
s.object.text = "aaa"
end if

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top