How do I delete my custom button on closing

  • Thread starter Thread starter N E Body
  • Start date Start date
N

N E Body

Hello everyone

I use the following code to create a button and run a macro - the problem is
how do I delete it when I close the workbook

Any Ideas

Kenny

I am using

Sub MyButton()
Set MenuItem = Application.CommandBars("Worksheet Menu
Bar").Controls.Add(Type:= _
msoControlButton)
With MenuItem
.FaceId = 277
.OnAction = "MyPass"
End With
End Sub
 
Hi Kenny,

Change:
Set MenuItem = Application.CommandBars("Worksheet Menu
Bar").Controls.Add(Type:= _
msoControlButton)

to

Set MenuItem = Application.CommandBars("Worksheet Menu Bar") _
.Controls.Add(Type:=msoControlButton, Temporary:=True)

Temporary controls are automatically deleted when Excel is closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top