[python-win32] Reading properties from office builtin dialogs?

Bob Gailer bgailer at alum.rpi.edu
Tue Jan 31 15:36:40 CET 2006


Anders Quist wrote:
> I have an application that wants to print a large set of documents.
> Therefore, I want to have word display its print dialog so the user
> can supply printer settings once, that I can read and store for use
> with all following prints.
>
> At first glance, this would seem straight-forward; VBA like so:
>
>     Dim dlgPrint As Dialog
>     Set dlgPrint = Dialogs(wdDialogFilePrint)
>     dlgPrint.Display
>     MsgBox "printer = " & dlgPrint.Printer
>
> However, when tried in python, the property Printer does not seem to
> be available. A little trial-and-error indicates that no such
> properties are available from Word builtin dialogs:
>
>     >>> import win32com.client
>     >>> x = win32com.client.Dispatch("Word.Application")
>     >>> p = x.Dialogs(win32com.client.constants.wdDialogFilePrint)
>     >>> p.Display()
>     <dialogs displayed>
>     >>> p.Printer
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in ?
>       File "c:\python\env\env11\lib\site-packages\win32com\client\__init__.py", line 451, in __getattr__
>         raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr)
>     AttributeError: '<win32com.gen_py.Microsoft Word 10.0 Object Library.Dialog instance at 0x21494960>' object has no attribute 'Printer'
>   
Odd - when I tried this win32com.client.constants did not have an 
attribute wdDialogFilePrint. When I substituted 88 then I got the 
printer dialog, and p.Printer returned my printer name!

Have you run makepy on word.application? If so note that attributes are 
case sensitive. Did you try p.printer?


More information about the Python-win32 mailing list