Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Deleting a button

Hi there.

I have a public variable called cbbGenerateReports as commandBarButton.
I then run the following code which puts the button on the toolbar very
nicely but I want to delete the button on close since everytime I open this
workbook, it adds the button again such that I end up with the same button
there several times!

Private Sub Workbook_Open()

Set cbbGenerateReports = _
Application.CommandBars("Tools").Controls.Add(msoC ontrolButton)

End Sub

I tried this but it didn't work on the BeforeClose event of the workbook.

Set cbbGenerateReports = _
Application.CommandBars("Tools").Controls.Item.Del ete(msoControlButton)

Any ideas?

Thanks!
--
www.brightfuture.ca/bright
My email address can be found on my site.
  #2   Report Post  
Posted to microsoft.public.excel.programming
PO PO is offline
external usenet poster
 
Posts: 66
Default Deleting a button

Hi Johnny

Omit the Set statement:

Application.CommandBars("Tools").Controls.Item.Del ete(msoControlButton)

NOT

Set cbbGenerateReports = _
Application.CommandBars("Tools").Controls.Item.Del ete(msoControlButton)


If it still doesn't work try to place
Application.CommandBars("Tools").Controls.Item.Del ete(msoControlButton)
in a public sub in a public module:

Sub RemoveControl()
Application.CommandBars("Tools").Controls.Item.Del ete(msoControlButton)
End Sub

and call it from the Workbook_BeforeClose sub:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call RemoveControl
End Sub

Hope this helps.

Regards
po


"Johnny Bright" wrote in message
...
Hi there.

I have a public variable called cbbGenerateReports as commandBarButton.
I then run the following code which puts the button on the toolbar very
nicely but I want to delete the button on close since everytime I open

this
workbook, it adds the button again such that I end up with the same button
there several times!

Private Sub Workbook_Open()

Set cbbGenerateReports = _
Application.CommandBars("Tools").Controls.Add(msoC ontrolButton)

End Sub

I tried this but it didn't work on the BeforeClose event of the workbook.

Set cbbGenerateReports = _

Application.CommandBars("Tools").Controls.Item.Del ete(msoControlButton)

Any ideas?

Thanks!
--
www.brightfuture.ca/bright
My email address can be found on my site.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting a button

cbbGenerateReports.Delete

--
Regards,
Tom Ogilvy

"Johnny Bright" wrote in message
...
Hi there.

I have a public variable called cbbGenerateReports as commandBarButton.
I then run the following code which puts the button on the toolbar very
nicely but I want to delete the button on close since everytime I open

this
workbook, it adds the button again such that I end up with the same button
there several times!

Private Sub Workbook_Open()

Set cbbGenerateReports = _
Application.CommandBars("Tools").Controls.Add(msoC ontrolButton)

End Sub

I tried this but it didn't work on the BeforeClose event of the workbook.

Set cbbGenerateReports = _

Application.CommandBars("Tools").Controls.Item.Del ete(msoControlButton)

Any ideas?

Thanks!
--
www.brightfuture.ca/bright
My email address can be found on my site.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Deleting a button

For some reason Excel wanted this to be within a With.. statement, but it
worked. Thanks!
I didn't try PO's suggestion because I'm lazy but it looks good too! Thanks
to both!

John

"Tom Ogilvy" wrote:

cbbGenerateReports.Delete

--
Regards,
Tom Ogilvy

"Johnny Bright" wrote in message
...
Hi there.

I have a public variable called cbbGenerateReports as commandBarButton.
I then run the following code which puts the button on the toolbar very
nicely but I want to delete the button on close since everytime I open

this
workbook, it adds the button again such that I end up with the same button
there several times!

Private Sub Workbook_Open()

Set cbbGenerateReports = _
Application.CommandBars("Tools").Controls.Add(msoC ontrolButton)

End Sub

I tried this but it didn't work on the BeforeClose event of the workbook.

Set cbbGenerateReports = _

Application.CommandBars("Tools").Controls.Item.Del ete(msoControlButton)

Any ideas?

Thanks!
--
www.brightfuture.ca/bright
My email address can be found on my site.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting a button

I didn't try PO's suggestion because I'm lazy but it looks good too!
Thanks
to both!

Not to me.

--
Regards,
Tom Ogilvy

"Johnny Bright" wrote in message
...
For some reason Excel wanted this to be within a With.. statement, but it
worked. Thanks!
I didn't try PO's suggestion because I'm lazy but it looks good too!

Thanks
to both!

John

"Tom Ogilvy" wrote:

cbbGenerateReports.Delete

--
Regards,
Tom Ogilvy

"Johnny Bright" wrote in

message
...
Hi there.

I have a public variable called cbbGenerateReports as

commandBarButton.
I then run the following code which puts the button on the toolbar

very
nicely but I want to delete the button on close since everytime I open

this
workbook, it adds the button again such that I end up with the same

button
there several times!

Private Sub Workbook_Open()

Set cbbGenerateReports = _
Application.CommandBars("Tools").Controls.Add(msoC ontrolButton)

End Sub

I tried this but it didn't work on the BeforeClose event of the

workbook.

Set cbbGenerateReports = _

Application.CommandBars("Tools").Controls.Item.Del ete(msoControlButton)

Any ideas?

Thanks!
--
www.brightfuture.ca/bright
My email address can be found on my site.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a Command Button Tdahlman Excel Discussion (Misc queries) 3 December 20th 07 08:34 PM
Deleting a Command Button from my Spreadsheet DDrowe Excel Discussion (Misc queries) 2 November 7th 06 01:49 PM
Deleting Command Button James W.[_2_] Excel Programming 0 January 11th 05 08:19 PM
Automation Error when deleting command bar button Frank Kabel Excel Programming 6 August 4th 04 04:09 PM
Deleting new control button on auto_close?? Simon Lloyd[_526_] Excel Programming 1 July 14th 04 01:13 AM


All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"