Patrick O'Beirne
unread,Jul 16, 2012, 5:51:43 AM7/16/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to exce...@googlegroups.com
On 13/07/2012 19:36, Nikee wrote:
> I did not get you. I have added ExcelCommand through ExcelDna...
>
> When can I add this below code ? In AutoOpen ?
Yes. I use the Ribbon class so had to try this in 2003 before posting:
Copied from a 2006 sample Dna project and amended:
<DnaLibrary Description="Sample Add-In">
<Project Language="VB">
<![CDATA[
' This class implements the ExcelDna.Integration.IExcelAddIn interface.
' This allows the add-in to run code at start-up and shutdown.
Class StartUp
Implements IExcelAddIn
Public Sub Start() Implements IExcelAddIn.AutoOpen
ExcelDnaUtil.Application.commandbars("&My Menu").controls("Ring
&Bell").FaceID=273
ExcelDnaUtil.Application.commandbars("&My Menu").controls("Say
&Hello").FaceID=59
End Sub
Public Sub Close() Implements IExcelAddIn.AutoClose
'Fires when addin is removed from the addins list but not when
excel closes
' - this is to avoid issues caused by the Excel option to
cancel out of the close after the event has fired.
MsgBox("Bye bye, from my DNA addin")
End Sub
End Class
Public Module MyTestFunctions
Function GetTheExcelVersion() as string
GetTheExcelVersion = ExcelDnaUtil.Application.Version
End Function
' An easy way to add a menu and menu items for a command....
' This command sounds a tone and sets cell C3 to the value 42
<ExcelCommand(MenuName:="&My Menu", MenuText:="Ring &Bell")> _
Sub RingBell()
Console.Beep()
Dim r as New ExcelReference(3,3)
r.SetValue(42)
End Sub
<ExcelCommand(MenuName:="&My Menu", MenuText:="Say &Hello")> _
Sub SayIt()
MsgBox("Hellooooo!")
End Sub
end module
]]>
</Project>
</DnaLibrary>