![]() |
adding button for add-in
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 |
All times are GMT +1. The time now is 05:10 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com