• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9. Advanced Word Hacks > 88. Use Python from Word

Use Python from Word

This hack shows you how to create standalone Python objects that you can run from within Word using VBA.

[Hack #85] showed you how to control Word from Python using COM automation [Hack #84] . Python also includes a way to create your own COM objects, which you can then use from within a Word macro.

Tip

This hack assumes that you have Python installed on your system and that you can run Python scripts from the DOS command line. To download Python (for free), go to http://www.python.org. For detailed information on using Python on Windows systems, see O’Reilly’s Python Programming on Win32.

This sample shows you how to create a COM object with a single method, SplitString. This method has semantics identical to the standard Python function string.split: the first argument is the string to split, and the second (optional) argument is the delimiter string.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint