Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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
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
Add a Button Programatically plus code jlclyde Excel Discussion (Misc queries) 1 December 9th 08 04:29 PM
VBA code for search button Dylan @ UAFC[_2_] Excel Worksheet Functions 3 November 25th 08 10:59 PM
configure add button & code [email protected] uk Excel Discussion (Misc queries) 7 November 24th 08 02:34 PM
Button, but now code Aaron Fude Excel Programming 2 May 16th 04 10:35 AM
Assign code to button Nic[_2_] Excel Programming 3 February 22nd 04 10:49 AM


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