Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Steven,
The first two sub below go into the ThisWorkbook object's codemodule, the last two into a regular module. The code will add a smiley button to the standard toolbar to fire the macro named MacroName (which should be in Module1). The button will be added when the file is opened, and removed when it is closed. HTH, Bernie Excel MVP Private Sub Workbook_Open() AddButton End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) DeleteButton End Sub 'Code below in standard module Module1 Public myBar As CommandBar Public myButton As CommandBarButton Sub AddButton() DeleteButton 'Create the new button Set myButton = myBar.Controls.Add(Type:=msoControlButton, ID:=2950) 'Set the properties of the new button With myButton .Caption = "Run my Macro" .OnAction = ThisWorkbook.Name & "!Module1.MacroName" End With End Sub Sub DeleteButton() Set myBar = Application.CommandBars("Standard") On Error Resume Next myBar.Controls("Run my Macro").Delete End Sub "Steven Revell" wrote in message ... Hi, I was wondering if it was possible to add a command to a toolbar on workbook open. i need to give it a name in case someone moves it. I then want to delete it on workbook close. Thanks in advance for any help, Steven |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Consecutive No'ing WHEN ADDING/DELETING ROWS | Excel Discussion (Misc queries) | |||
Adding macros to toolbars | Excel Discussion (Misc queries) | |||
Adding and deleting rows with formulas ****Need Help**** | Excel Discussion (Misc queries) | |||
Sequential number - adding and deleting rows | Excel Discussion (Misc queries) | |||
how to protect sheet from adding/deleting | Excel Discussion (Misc queries) |