<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2912" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Verdana size=2>
<DIV><FONT face=Verdana size=2><SPAN class=921350310-19072006>Hi 
all,</SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN 
class=921350310-19072006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2><SPAN class=921350310-19072006>I'm trying to 
extend the RMB popup menu in Excel to let the user easily select the project 
she's working on. The construction of the (hierarchical) menu is written in a 
Python COM server. This server is used by some VBA code in the paricular 
workbook (a 'timesheet'), in the Workbook_Open() function.</SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN 
class=921350310-19072006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2><SPAN class=921350310-19072006>The problem is 
that i can't seem to set the (event-) callback function, ie what happens when a 
user selects a given menu item. Below is the code I'd hoped would work but 
doesn't:</SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN 
class=921350310-19072006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2>excel = 
Dispatch("Excel.application")</FONT></DIV>
<DIV><FONT face=Verdana size=2>cbr = excel.CommandBars("Cell")</FONT></DIV>
<DIV><FONT face=Verdana size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=921350310-19072006><FONT face=Verdana size=2># make a 
sub-menu</FONT></SPAN></DIV>
<DIV><FONT face=Verdana size=2>smp = cbr.Controls.Add(Type = 
constants.msoControlPopup)</FONT></DIV>
<DIV><FONT face=Verdana size=2>smp.Caption = "[BB] Projecten"</FONT></DIV>
<DIV><FONT face=Verdana size=2>smp.Tag = "[BB] Projecten"<BR></FONT></DIV>
<DIV><FONT size=+0><SPAN class=921350310-19072006><FONT face=Verdana size=2># 
make a menu item</FONT></SPAN></DIV></FONT>
<DIV><FONT face=Verdana size=2>smpo = CastTo(smp, 
"CommandBarPopup")</FONT></DIV>
<DIV><FONT face=Verdana size=2>nc = smpo.Controls.Add(Type = 
constants.msoControlButton)</FONT></DIV>
<DIV><FONT face=Verdana size=2>nc.Caption = "Butt"</FONT></DIV>
<DIV><SPAN class=921350310-19072006><FONT face=Verdana size=2># 
callback</FONT></SPAN></DIV>
<DIV><FONT face=Verdana size=2>nc.OnAction = onProject<SPAN 
class=921350310-19072006>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # &lt;-- 
PROBLEM</SPAN><BR></FONT></DIV>
<DIV><FONT size=+0><SPAN class=921350310-19072006><FONT face=Verdana 
size=2></FONT></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=+0><SPAN class=921350310-19072006><FONT face=Verdana 
size=2>onProject()&nbsp;can be a global function, an instancemethod or a 
staticmethod, it always says this: &lt;exceptions.TypeError: Objects of type 
'function' can not be converted to a COM VARIANT&gt;.</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN 
class=921350310-19072006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=+0><SPAN class=921350310-19072006><FONT face=Verdana size=2>I 
did some research and came up with the following 
strategy:</FONT></SPAN></FONT></DIV>
<DIV><FONT size=+0><SPAN class=921350310-19072006><FONT face=Verdana size=2>a. 
Write a callback class, deriving from some COM 
interface</FONT></SPAN></FONT></DIV>
<DIV><FONT size=+0><SPAN class=921350310-19072006><FONT face=Verdana size=2>b. 
Convert (an object of) this class to&nbsp;the appropriate&nbsp;'COM 
VARIANT'</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN 
class=921350310-19072006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2><SPAN class=921350310-19072006>My questions 
are:</SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN class=921350310-19072006>1. Is this the way 
to do this? If not, what is?</SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN class=921350310-19072006>2. If so, what is 
the interface to inherit from? Functions to override (eg 
Invoke())?</SPAN></FONT></DIV>
<DIV><FONT size=+0><SPAN class=921350310-19072006><FONT face=Verdana><FONT 
size=2>3. Do I use pythoncom.WrapObject() for b.? If so, what should be&nbsp;my 
gatewayIID&nbsp;&amp; interfaceIID?</FONT></FONT></SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN 
class=921350310-19072006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2><SPAN 
class=921350310-19072006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2><SPAN class=921350310-19072006>Thank you very 
much for your time,</SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN 
class=921350310-19072006>g</SPAN></FONT></DIV>
<DIV><FONT face=Verdana size=2><SPAN 
class=921350310-19072006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana size=2><SPAN class=921350310-19072006>PS: In VBA you 
have to give it the name of a macro, eg nc.OnAction = 
Macro1.</SPAN></FONT></DIV>
<DIV><FONT size=+0><SPAN class=921350310-19072006><FONT face=Verdana 
size=2></FONT></SPAN>&nbsp;</DIV></FONT></FONT></DIV></BODY></HTML>