Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    milton keynes, Buckinghamshire
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deleting buttons (2003)

    I had a worksheet which had buttons on it which were created from the Control Box menu. However the buttons kept on re-sizing each time I ran macros. I therefore replaced the Control Box buttons with buttons from the Forms menu.

    Part of my macro exports the Forecasting worksheet and deletes the buttons, before saving the exported workbook. The following code used to work well:
    .Worksheets("Forecasting").Shapes("CommandButton2" ).Delete
    .Worksheets("Forecasting").Shapes("CommandButton3" ).Delete
    .Worksheets("Forecasting").Shapes("CommandButton4" ).Delete
    However, I cannot work out how to address the new buttons that come from the Forms menu so as to delete them. Can somebody please provide guidance on addressing these buttons.

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Deleting buttons (2003)

    The same way, the only difference is in the names. Command buttons from the Forms toolbar are named Button 1, Button 2 etc. by default instead of CommandButton1, CommandButton2 etc.

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Deleting buttons (2003)

    You could use:
    <pre>Dim btn as Button
    for each btn in .Worksheets("Forecasting").buttons
    btn.delete
    next btn
    </pre>

    and not worry about the names.
    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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