Reputation: 2125
The animation below depicts the manual change of a text inside a TextBox
AFTER the TextBox
has been grouped with another shape ( an msoShapeOval
).
Q: How to perform the same task in VBA ?
I tried the following code - it groups the two shapes correctly but after that it fails at the last line:
Sub ChangeTextAfterGrouping()
Dim shp As Shape
Dim tb As Shape
Dim ShpArray() As Variant
Set shp = ActiveSheet.Shapes.AddShape(msoShapeOval, 200, 40, 120, 70)
Set tb = ActiveSheet.Shapes.AddTextBox(msoTextOrientationHorizontal, 235, 65, 50, 20)
tb.TextFrame.Characters.Text = "ABC" 'Success
ReDim ShpArray(1 To 2)
ShpArray(1) = shp.Name
ShpArray(2) = tb.Name
ActiveSheet.Shapes.Range(ShpArray).Group
tb.TextFrame.Characters.Text = "XYZ" 'Error
End Sub
Other people are reporting the same problem. See:
https://www.excelforum.com/excel-programming-vba-macros/388251-editing-text-in-text-box-grouped-within-a-trapezoid.html
Upvotes: 0
Views: 276
Reputation: 170
In my Office 2007 your code works pretty well with no error.
Upvotes: 0