+ Reply to Thread
Results 1 to 13 of 13

Error deleting button shape

  1. #1
    Registered User
    Join Date
    08-03-2018
    Location
    Toronto, Ontario, Canada
    MS-Off Ver
    2016
    Posts
    8

    Error deleting button shape

    Using Windows 10, Excel 2016. The code is in a Module.

    The code worked when written in 2015. Now it throws errors. The text of the error messages is different from that in the other threads with the same error codes.

    The code attempts to locate a button by its caption and delete it. There is only one button per worksheet.

    DeleteShapesByCaption "Create a new Schedule of Values tab", wSht

    Please Login or Register  to view this content.
    The error always occur at the first occurance of Shp.Delete

    RTE 404 Object Required or RTE -2147024809 (80070057) The specified value is out of range

    Context:

    The workbook has a worksheet which is a template. Once the template is filled in, it is copied for month 1. After the month 1 sheet is completed, the create_a_new_sheet_button is clicked to create a new sheet for month 2 and the create_a_new_sheet_button is supposed to be removed from the month 1 sheet. Each sheet only has one button.

    I have used debug.print to confirm that the activesheet is the previous month's sheet.

    I have modified cell formulae to reflect changes in legislation, but I don't think those changes are relevant because now even the original 2015 workbook produces the errors.

    The code executes as expected in creating the month 1 sheet. The only difference is that the create_a_new_sheet button is not deleted from the template page.

    I can change the caption and disable the button as an error free work around, but it would be preferable to delete it.
    Last edited by alansidman; 08-03-2018 at 12:01 PM. Reason: code formatting

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,885

    Re: Error deleting button shape

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Error deleting button shape

    If Shp.OLEFormat.Object.Object.Caption = Caption Then
    I don't see where caption is set....

  4. #4
    Registered User
    Join Date
    08-03-2018
    Location
    Toronto, Ontario, Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: Error deleting button shape

    The Caption is set in the template that is being copied. It exists and is properly found.

  5. #5
    Registered User
    Join Date
    08-03-2018
    Location
    Toronto, Ontario, Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: Error deleting button shape

    I am attempting to delete the button that launched the code in the first place. Is that a problem?

  6. #6
    Registered User
    Join Date
    08-03-2018
    Location
    Toronto, Ontario, Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: Error deleting button shape

    The Caption is set in the worksheet template that is being copied. It exists and is properly found.

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Error deleting button shape

    Okay, if you want to delete the button with a particular caption then.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-03-2018
    Location
    Toronto, Ontario, Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: Error deleting button shape

    Your code executes without error when inserted into my code. Thank you. I still don't know why what worked before no longer works.

  9. #9
    Registered User
    Join Date
    08-03-2018
    Location
    Toronto, Ontario, Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: Error deleting button shape

    Apologies. The different forums have different rules and when I saw it didn't format properly, I tried, but wasn't allowed to edit the post to fix it.

  10. #10
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Error deleting button shape

    I don't know what you are asking.
    Is this question solved?

  11. #11
    Registered User
    Join Date
    08-03-2018
    Location
    Toronto, Ontario, Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: Error deleting button shape

    The problem is resolved in that I now have a way to delete the button, which was the original intent. What I don't understand is why code that worked perfectly in 2015 has stopped working and now produces errors. Since the code didn't change, what changed in Excel, VBA or Windows to break the code?

  12. #12
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Error deleting button shape

    I don't know what time line you are working on, there was an issue a couple years ago with a windows update that screwed up the activeX controls.

  13. #13
    Registered User
    Join Date
    08-03-2018
    Location
    Toronto, Ontario, Canada
    MS-Off Ver
    2016
    Posts
    8

    Re: Error deleting button shape

    That may have been it, but no users reported any problems and I only discovered it myself when updating the file content to work with new legislation.

    Thanks for the assist.

+ 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. [SOLVED] Deleting a particular shape from workbook
    By hegdep in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2017, 04:04 AM
  2. Trying to change shape color when selecting toggle button - Code gives Error
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-01-2016, 01:38 PM
  3. [SOLVED] Shape as a button to replace a Command Button which operates conditional format.
    By A440 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2015, 05:46 PM
  4. [SOLVED] deleting picture (shape)
    By TimlmiT in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2014, 10:13 AM
  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. [SOLVED] Clear Contents of Shape Without Deleting Shape
    By AlvaroSiza in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-17-2012, 09:00 AM

Tags for this Thread

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