Button, but now code

A

Aaron Fude

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
 
E

Edwin Tam

Try to assign the macro below to the button.
You can easily change the values of the variables to make it work in your case.

'---------------------------------------------------------
Private Sub CommandButton1_Click()
Dim response
Dim file_name As String
Dim macro_name As String

file_name = "file_name_of_addin.xla"
macro_name = "name_of_macro_to_execute"

response = MsgBox("Would you like to enable macros", vbYesNo + vbQuestion)

If response = vbYes Then
Application.Run Macro:="'" & file_name & "'!" & macro_name
End If
End Sub

'---------------------------------------------------------

Regards,
Edwin Tam
[email protected]
http://www.vonixx.com


----- Aaron Fude wrote: -----

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
 
B

Bob Phillips

Why post twice? I replied to the other one.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top