On Tue, 31 Jan 2006 10:32:59 +0100, Anders Quist <[EMAIL PROTECTED]> 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. >... > >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' > >What am I doing wrong? > Your example works fine for me, as long as I open a document between the call to Dispatch and the call to fetch the dialog. The print dialog doesn't work unless a document is open. >>>import win32com.client >>>x = win32com.client.Dispatch("Word.Application") >>>p = x.Dialogs(88) Traceback (most recent call last): File "<input>", line 1, in ? File "C:\Apps\Python24\Lib\site-packages\win32com\client\dynamic.py", line 165, in __call__ return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None) com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'This method or property is not available because a >>>document window is not active.', 'C:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\wdmain11.chm', 37373, -2146823683), >>>None) >>>x.Visible = 1 (At this point, I manually went over to the window and opened a file, because I didn't want to go look up the DOM command to do it...) >>>p = x.Dialogs(88) >>>p.Display() -1 >>>p.Printer u'\\\\DOUG\\HP LaserJet 5Si - PS' >>> That certainly is the name of my default printer. -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32