Getting Started with DiscoveryScript

DiscoveryScript is a free Microsoft Excel® addin that makes it very easy for you to create macros or scripts for Excel using Python.

DiscoveryScript takes care of all the Excel-addin-plumbing. All you have to do is create a Python script and put it in c:\Xefion\Scripts, then DiscoveryScript will automatically create Excel menu items that call your script.

Installation

Click here to download DiscoveryScript.

System requirements: DiscoveryScript requires Excel XP, 2003 or 2007.

Python version: DiscoveryScript uses the Microsoft IronPython 1.1 interpreter.

Removing the DiscoveryScript Add-in

You can uninstall DiscoveryScript through the Add or Remove Programs functionin the Windows Control Panel on Windows XP or the Programs and Features function in the Windows Control Panel on Windows Vista.

DiscoveryScript Menu

After installing DiscoveryScript, Excel will have an extra menu in the menu-line. In Excel 2007, it looks like this:

Trying the Sample Scripts

The DiscoveryScript installer puts two short samples scripts in the c:\Xefion\Scripts folder. Use can see them as menu items in the DiscoveryScript menu with the names "One Liner" and "A Few More Lines":

The One Liner.py script contains a single line of code:

excel.ActiveSheet.Range['B3'].Value2 = "DiscoveryScript One Liner"

This line simple writes the text 'DiscoveryScript One Liner' into cell B3 of the current worksheet. If you click the menu item, the worksheet will look like this:

Using the Interactive Console

DiscoveryScript includes an interactive console that you can use for trying out Python commands and the Excel object model.

Click the 'Console' menu item in the DiscoveryScript menu to open up the console window.

This screenshot shows the window and some sample commands:

Creating Your First Script

To use a script, simply put the file in the c:\Xefion\Scripts folder. The file name extension must be 'py'.

You can use any text editor, for example the Notepad editor that comes with Windows.

After restarting Excel, you'll see a menu item for your script in the DiscoveryScript menu:

If you execute the script by clicking the menu item, you'll get this result:

Resources

www.python.org is the official website for the Python programming language.

The IronPython project is hosted at Microsoft's Codeplex website.

Go to Microsofts website for information about the Excel object model.