Deleting CommandButton after running macro

Anonymous
2016-07-18T14:57:37+00:00

I'm trying to delete the CommandButton that runs my macro. The rest of the code simply locks every sheet after the first sheet. Here's my code:

Private Sub CommandButton1_Click()

For i = 2 To Sheets.Count

    Sheets(i).Activate                                   'Locks every other sheet

    ActiveSheet.Protect Password:="Microsoft"

Next i

Sheets(1).Shapes("CommandButton1").Delete                'Deletes button

Sheets(1).Protect Password:="Microsoft"                  'Locks first sheet

End Sub

Everything runs fine with no error, but the CommandButton is still there after the macro has ran.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Newest
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more