Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Check Existing Button

I'm using the following VBA code to create a button in Excel that runs a
macro. The code is in the Workbook_Open procedure. I use the .Delete
method in the Workbook_Beforeclose procedure to remove the button when the
workbook is closed.

Dim oCb As CommandBar
Dim oCtl As CommandBarButton
Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls.Add( _
Type:=msoControlButton, _
Temporary:=True)
oCtl.Caption = "My Button."
oCtl.OnAction = "My Macro"
oCtl.FaceId = 270
oCtl.Style = msoButtonIconAndCaption
End With


Is there a way using VBA to see if the button already exists so as not to
create a duplicate button?


Thanks in advance..

Mike


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Check Existing Button

Don't bother, just delete it regardless

On Error Resume Next
Application.CommandBars("Worksheet Menu
Bar").Controls("myButton").Delete
On Error Goto 0

before this code

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mike" wrote in message
...
I'm using the following VBA code to create a button in Excel that runs a
macro. The code is in the Workbook_Open procedure. I use the .Delete
method in the Workbook_Beforeclose procedure to remove the button when the
workbook is closed.

Dim oCb As CommandBar
Dim oCtl As CommandBarButton
Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls.Add( _
Type:=msoControlButton, _
Temporary:=True)
oCtl.Caption = "My Button."
oCtl.OnAction = "My Macro"
oCtl.FaceId = 270
oCtl.Style = msoButtonIconAndCaption
End With


Is there a way using VBA to see if the button already exists so as not to
create a duplicate button?


Thanks in advance..

Mike




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
Check for existing sheet in book benjammind Excel Programming 2 July 4th 05 01:53 PM
Adding Code to an Existing Command Button with VBA jasoncw[_2_] Excel Programming 1 February 15th 05 11:15 PM
How to correct this formula and check if more issues are existing? Metallo[_3_] Excel Programming 9 October 27th 04 01:38 PM
Macro Help - check existing tabs Macro Help[_2_] Excel Programming 1 July 27th 04 05:15 PM
Creating a Button to add to existing values while subtracting range C. A. Zan Excel Programming 1 February 23rd 04 10:07 AM


All times are GMT +1. The time now is 02:37 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"