+ Reply to Thread
Results 1 to 5 of 5

Set Shape as Another Shape Fails.. ??

  1. #1
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    Set Shape as Another Shape Fails.. ??

    The following code fails:

    Please Login or Register  to view this content.
    gives the following error:
    Run-Time error '-2147024809 (80070057)':
    The item with the specified name wasn't found

    the shape with the name "GroupName" does not exist, but my function returns true that it does exist. Not sure why. Please help. Thanks.

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Set Shape as Another Shape Fails.. ??

    Use F8 to step through your code. You'll see that tmpID is never empty (even for a shape that does not exist).
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    Re: Set Shape as Another Shape Fails.. ??

    Thank-you. It's weird but after I changed the code to this:

    Please Login or Register  to view this content.
    it now works as intended.

    I use the function extensively to check if shapes exist, and create or destroy them depending on whether they should exist. It's all working as intended. I am now puzzled - why does this new code work? Thanks!

  4. #4
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Set Shape as Another Shape Fails.. ??

    Because when ShapeName does not exist, WS.Shapes(ShapeName).ID does generate an error (but tmpID gets a value of 0 so it is not empty). In your initial code you told it to 'Resume Next' which means ignore the error. So, your code goes through the else clause EVERY time and Shapes_Exist is set to TRUE. In your second code, you tell it to skip over the if/else if there is an error. So, you set Shapes_Exist to False, an error occurs, and you exit, which is what you want.

    You can actually remove the if/else clause and just keep the code in your else block since IsEmpty() will always be FALSE.

  5. #5
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    Re: Set Shape as Another Shape Fails.. ??

    THANKS!!!

    Yes, I rarely use On Error Resume Next. I had borrowed the code from some website, which is where it came from, but when I was debugging, I changed it around to my coding style. Thanks so much for helping me understand this!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Shape fill from URL fails on Mac Excel 2011
    By SnugglesMcWal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2016, 09:00 PM
  2. Shape buttons - Switch background image of shape on click and exit - referenced jpg
    By ApatheticAndrew in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-14-2015, 08:06 AM
  3. Assign macro with parameter to shape based on shape location
    By bobo3127 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2014, 11:18 AM
  4. Replies: 13
    Last Post: 12-10-2013, 12:51 PM
  5. [SOLVED] Use a button to control a macro that inserts an image into a shape or resets the shape
    By nwb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2013, 04:41 PM
  6. Add command button to shape and change shape color on mouseover
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2012, 05:12 PM
  7. Replies: 0
    Last Post: 11-30-2012, 01:29 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1