Detroit Coder

Coding in the D and other interesting things

Video: Call Python from Excel Formulas

In this post I am going to quickly explain how to create Excel formulas that call class methods that are written completely in Python. I will be using the rottenTom class created in my previous post to create some Excel formulas such as ‘=getyear(“space jam”)’ and have it return 1996 in the Cell.

To do this I use pywin32¬†and register my rottenTom class as a COM server. COM is Microsoft’s way of exposing interfaces for code that are language agnostic. This allows you to create a Python class and instantiate it within VBA, as we will see in this example. If you have not worked with COM before, Activestate has a good overview of setting up a COM server and Mark Hammond (the guy you thank at the end of every Python install on Windows) has an old but still very pertinent book on Python on Windows. Chapter 12 is specifically dedicated to Python and COM.

About these ads

2 comments on “Video: Call Python from Excel Formulas

  1. robert
    November 28, 2013

    excellent job here. thanks
    Can you also put up one about calling Python code from VBA

    • Michael David Watson
      November 29, 2013

      Absolutely, is there anything in particular that you would be most interested in if I make a post just about calling Python from VBA?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


This entry was posted on November 26, 2013 by .

Get every new post delivered to your Inbox.

%d bloggers like this: