Consulting

Results 1 to 5 of 5

Thread: Application.Caller error for AutoShapeType 152

  1. #1
    VBAX Newbie
    Joined
    Mar 2005
    Posts
    3
    Location

    Application.Caller error for AutoShapeType 152

    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)

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    I'm guessing that the names are defined differently and Caller <> Name


    Capture.JPG




    Capture2.JPG



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

    Capture3.JPG
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Mar 2005
    Posts
    3
    Location
    Thank you very much for the reply Paul.
    I'll be able to adapt your solution to carry on.

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Application.Caller only returns 31 characters, and some shapes have longer names than that by default, hence the error.
    Be as you wish to seem

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Interesting

    Thanks for enlightening me
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •