View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Editing text in text box grouped within a trapezoid

Hi DM,

For me it's not necessary to select a grouped item to return the text, and I
can't select a grouped item even if I want to. On which point this line in
your example
shpTextbox.Select
errors for me with permission denied

If you are able select a grouped item the only thing I can think of is there
must be some version difference, I'm using XL2K. Don't have later version to
hand but from memory don't think it worked in any version.

I was optimistic for a moment you had come up with something with the
Formula property, I had never thought of that. Sadly I cannot get that to
work despite trying various other ways.

So we are working with similar objects can you incorporate your formula
approach or select a grouped item in the following, say in the loop after
the Msgbox.

Sub test()
Dim v(1 To 4), i
Dim shp As Shape
Dim gi As Object
Dim ws As Worksheet

Set ws = ActiveSheet
ws.DrawingObjects.Delete

'first make 4 texboxes & group
For i = 1 To 4
Set shp = ws.Shapes.AddTextbox(1, 20, i * 20, 50, 15)
shp.TextFrame.Characters.Text = Chr(i + 64)
v(i) = shp.Name
Next
Set shp = ws.Shapes.Range(v).Group
Application.ScreenUpdating = True

i = 0
For Each gi In shp.GroupItems
i = i + 1
MsgBox gi.TextFrame.Characters.Text, , gi.Name

'gi.TextFrame.Characters.Text = i & " text"
'#1004 unable to set the text property

'gi.Select
'#70 Permission denied
Next

End Sub

It's also possible to get to the text in an object that supports it at the
DrawingObject level, even in a grouped object, simply
s = ob.Text or ob.Text = s

FWIW I find this level significantly faster to read/write than
shape.textframe. However still not possible to write if grouped.

I'm glad you're perservering with this, I gave up a long time ago!

Regards,
Peter T

"DM Unseen" wrote in message
oups.com...
Peter,

I showed that you need to select the item in the group to actually get
the text (and you can also clear the text as well). but setting it
errors out (grrrrrrrrrrrrrrr) whatever I try. So i guess you're right
in the sense that Excel VBA does not allow you to set individual texts
of shapes directly through VBA:(

There is a workaround however(a quite nice one as well). Each shape
that can contain text also has a formula property so you could work
around this with linking to a cell and then removing the link:)

Sub t()
Dim shpTextbox As Shape
Dim shpGroup As Shape


Set shpGroup = ActiveSheet.Shapes(2)
Set shpTextbox = shpGroup.GroupItems(2)
shpTextbox.Select
Range("A1") = "mytext"
Selection.Formula = "=A1"
Selection.Formula = vbNullString
Debug.Print Selection.Characters.Text
Debug.Print Selection.Formula
End Sub

This is getting fun!

You could of course leave the formula, that would be way better, but it
works!!!!!

DM Unseen