PDA

View Full Version : [SOLVED] Application.Caller error for AutoShapeType 152



Cutter
02-24-2019, 07:50 AM
Good morning all.

I have run into a problem that I haven't been able to solve by searching.

I have a series of Rectangles with Top Rounded Corners (AutoShapeType 152). I am trying to assign a single macro to perform various tasks depending on the Text within the Shape. To do that I am trying to get the Text of the Shape using ActiveSheet.Shapes(Application.Caller). This method works fine with a Rectangle with Rounded Corners (AutoShapeType 5) but not with Type 152. I can carry on using the Type 5 but I'm determined to know why this is giving an error. Thanks for your interest.

The simplified code is:


Sub ShapeTest()
Dim shp As Shape, str As String
Set shp = ActiveSheet.Shapes(Application.Caller)
str = shp.TextFrame.Characters.Text
MsgBox str
End Sub


The result is: Run-time error '-2147024809 (80070057)': The item with the specified name wasn't found
On Debug the highlighted line is: Set shp = ActiveSheet.Shapes(Application.Caller)

Paul_Hossler
02-24-2019, 09:38 AM
I'm guessing that the names are defined differently and Caller <> Name


23798




23799



If you give the Shape your own name, you can identify it and act on it

23800


Option Explicit
Sub ShapeTest()
Dim shp As Shape, str As String, sCaller As String

sCaller = Application.Caller

For Each shp In ActiveSheet.Shapes
If sCaller = shp.Name Then
str = shp.TextFrame.Characters.Text
MsgBox str

Exit For
End If
Next
End Sub

Cutter
02-24-2019, 10:43 AM
Thank you very much for the reply Paul.
I'll be able to adapt your solution to carry on.

Aflatoon
02-26-2019, 04:52 AM
Application.Caller only returns 31 characters, and some shapes have longer names than that by default, hence the error.

Paul_Hossler
02-26-2019, 06:39 AM
Interesting

Thanks for enlightening me