Re: [ExcelDna] Add Image for Excel Command

240 views
Skip to first unread message

Patrick O'Beirne

unread,
Jul 13, 2012, 12:12:56 PM7/13/12
to exce...@googlegroups.com
On 13/07/2012 17:05, Nikee wrote:
> I have two ExcelCommand; they appear under in AddIn Ribbon in Excel. I
> want to assign Image for both of them. How can I do this ? --


somesheet.Shapes(somename).Copy

commandbarobject.controls(itsname).PasteFace


or to use a builtin MS face id
commandbarobject.controls(itsname).FaceId = 123

Patrick O'Beirne

unread,
Jul 16, 2012, 5:51:43 AM7/16/12
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>


Reply all
Reply to author
Forward
0 new messages