Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Button, but no code
Hi,
I'm supplying my colleagues with an addin but also with a spreadsheet that has a button on it. I would prefer it if the button could call the code from the addin rather than a callback within the spreadsheet. This would save them the "Would you like to enable macros?". Very many thanks in advance, Aaron |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Button, but no code
Add the button to a toolbar when the add-in starts. Add this code to the
ThisWorkbook code module of the add-in Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim NewItem As CommandBarControl Dim oCB As CommandBar Dim NewItemName As String Set oCB = Application.CommandBars("Formatting") sbutton = "myButton" On Error Resume Next oCB.Controls(sbutton).Delete On Error GoTo 0 End Sub Private Sub Workbook_Open() Dim NewItem As CommandBarControl Dim oCtl As CommandBarControl Dim oCB As CommandBar Dim NewItemName As String Set oCB = Application.CommandBars("Formatting") sbutton = "myButton" On Error Resume Next oCB.Controls(sbutton).Delete On Error GoTo 0 Set oCtl = oCB.Controls.Add(Type:=msoControlDropdown, _ temporary:=True) With oCtl .Caption = sbutton .OnAction = "myMacro" .BeginGroup = True End With End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Aaron Fude" wrote in message ... Hi, I'm supplying my colleagues with an addin but also with a spreadsheet that has a button on it. I would prefer it if the button could call the code from the addin rather than a callback within the spreadsheet. This would save them the "Would you like to enable macros?". Very many thanks in advance, Aaron |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Button, but no code
Nice. Thank you.
"Bob Phillips" wrote in message ... Add the button to a toolbar when the add-in starts. Add this code to the ThisWorkbook code module of the add-in Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim NewItem As CommandBarControl Dim oCB As CommandBar Dim NewItemName As String Set oCB = Application.CommandBars("Formatting") sbutton = "myButton" On Error Resume Next oCB.Controls(sbutton).Delete On Error GoTo 0 End Sub Private Sub Workbook_Open() Dim NewItem As CommandBarControl Dim oCtl As CommandBarControl Dim oCB As CommandBar Dim NewItemName As String Set oCB = Application.CommandBars("Formatting") sbutton = "myButton" On Error Resume Next oCB.Controls(sbutton).Delete On Error GoTo 0 Set oCtl = oCB.Controls.Add(Type:=msoControlDropdown, _ temporary:=True) With oCtl .Caption = sbutton .OnAction = "myMacro" .BeginGroup = True End With End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Aaron Fude" wrote in message ... Hi, I'm supplying my colleagues with an addin but also with a spreadsheet that has a button on it. I would prefer it if the button could call the code from the addin rather than a callback within the spreadsheet. This would save them the "Would you like to enable macros?". Very many thanks in advance, Aaron |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Button, but no code
It's a pleasure.
-- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Aaron Fude" wrote in message ... Nice. Thank you. "Bob Phillips" wrote in message ... Add the button to a toolbar when the add-in starts. Add this code to the ThisWorkbook code module of the add-in Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim NewItem As CommandBarControl Dim oCB As CommandBar Dim NewItemName As String Set oCB = Application.CommandBars("Formatting") sbutton = "myButton" On Error Resume Next oCB.Controls(sbutton).Delete On Error GoTo 0 End Sub Private Sub Workbook_Open() Dim NewItem As CommandBarControl Dim oCtl As CommandBarControl Dim oCB As CommandBar Dim NewItemName As String Set oCB = Application.CommandBars("Formatting") sbutton = "myButton" On Error Resume Next oCB.Controls(sbutton).Delete On Error GoTo 0 Set oCtl = oCB.Controls.Add(Type:=msoControlDropdown, _ temporary:=True) With oCtl .Caption = sbutton .OnAction = "myMacro" .BeginGroup = True End With End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Aaron Fude" wrote in message ... Hi, I'm supplying my colleagues with an addin but also with a spreadsheet that has a button on it. I would prefer it if the button could call the code from the addin rather than a callback within the spreadsheet. This would save them the "Would you like to enable macros?". Very many thanks in advance, Aaron |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Add a Button Programatically plus code | Excel Discussion (Misc queries) | |||
VBA code for search button | Excel Worksheet Functions | |||
configure add button & code | Excel Discussion (Misc queries) | |||
Button, but now code | Excel Programming | |||
Assign code to button | Excel Programming |