Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
This is the sort of code I use, without any problems: Private Sub Workbook_Open() 'these three lines are necessary incase excel closed due to an 'error e.g Dr Watson. On Error Resume Next Application.CommandBars("standard").Controls("Form at me").Delete On Error GoTo 0 Set oCtl = Application.CommandBars("standard") With oCtl.Controls.Add(msoControlButton) .BeginGroup = True .Caption = "Format me" .OnAction = "Mymacro" .FaceId = 527 End With end sub also I'd have: Private Sub Workbook_BeforeClose(Cancel As Boolean) 'to delete the button when the workbook closes On Error Resume Next Application.CommandBars("standard").Controls("form at me").Delete On Error GoTo 0 End Sub Regards J "cg" wrote in message ... Hi all, I created an add-in with the following code in it's open event. My problem is this button is created everytime a workbook is opened. yikes! Should I look for the button before adding it and if so how? Is this the best way to add a button for my macro in the add-in? Any help would be greatly appreciated. Private Sub Workbook_Open() Dim oCtl As CommandBarControl With Application.CommandBars("standard") Set oCtl = .Controls.Add(Type:=msoControlButton) With oCtl .BeginGroup = True .Caption = "Format me" .OnAction = "Mymacro" .FaceId = 527 End With End With End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Adding a Button | Excel Discussion (Misc queries) | |||
adding a button to a tool bar | Excel Worksheet Functions | |||
Adding a button to a spreadsheet... | Excel Discussion (Misc queries) | |||
Adding Button to Tool Bar | Excel Discussion (Misc queries) | |||
adding button for add-in | Excel Programming |