problem with beforeclose event

  • Thread starter Thread starter Gordon
  • Start date Start date
G

Gordon

Hi,

If I run the line below in the immediates window it works.

CommandBars("standard").Controls.Item(5).Delete

It deletes the fifth control on my toolbar.

Yet it gives me an error when its run on the Before close
event where I need it for my Excel add-in.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
CommandBars("standard").Controls.Item(5).Delete
End Sub

This gives me an error and I can't figure out why.

This is the error:
Runtime error 91 Object variable or With Block variable
not set

If I make this an Auto_Close macro this line of code
works. something about the before close event of the
workbook makes it not work!

Any Ideas?

Thanks in advance

Gordon
 
Gordon,

For some reason adding "Application" makes it work for me:

Application.CommandBars("Standard").Controls.Item(5).Delete

hth,

Doug Glancy
 

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