[python-win32] com, CreateObject, and py2exe
Mark Hammond
skippy.hammond at gmail.com
Thu Feb 24 02:29:13 CET 2011
On 24/02/2011 11:25 AM, Bill Purcell wrote:
...
> I then have a function in VBA inside excel which accesses this server
> with Obj = CreateObject("Nevco.Modules"). I would like to share this
> code with a couple coworkers who are not interested in learning
> python, so I would like to create an executable to start the server
> for them.
I think there might be a misconception here - the if name=='__main__'
block is *only* doing registration and unregistration - the COM object
is not running in that process. Excel will be loading the COM object
in-process and manage its lifetime itself. There really isn't a need to
have your main block like that - you can just register it once and leave
it registered until explicitly unregistered.
> setup(
> name="Nevco Excel",
> version="0.1",
> description='Functions to use inside excel.',
> author='Bill Purcell',
> author_email='bpurcell at nevco.com',
> com_server=["win32com.servers.interp"],
> options = {'py2exe': {'includes': 'numpy'}},
You want the com_server element to refer to your COM module - as
specified, your object will expose the 'python.interpreter' sample
object for use.
What should happen is that py2exe will create a DLL (and possibly a
.exe) for you - but similarly to as mentioned above, this DLL is loaded
by excel automatically - you just register it once (probably via
regsvr32.exe) and Excel can then use it as necessary. Note however that
the registration will need to be done by an elevated administrator
account on Windows 7 - but once registered a regular user can use it.
The most common approach is to use an installer like Wise or nsis to
perform the installation and registration after prompting for elevation.
> Also, I would like to eventually move towards maybe writing an
> Add-in. Does anyone have any "Hello World" excell Add-in tutorials
> for Python?
Check out the win32com\Demos directory - but AFAIK, the excel samples
there haven't been tested with recent versions of excel.
HTH,
Mark
More information about the python-win32
mailing list