Python and Word OLE

tdsperth at gmail.com tdsperth at gmail.com
Mon Jan 18 18:53:40 EST 2016


On Friday, January 15, 2016 at 2:04:08 PM UTC+8, tdsp... at gmail.com wrote:
> Hi All
> 
> I am trying to change the active printer using win32com.client with the following code 
> 
> 
> 
> wordapp = win32com.client.Dispatch('Word.Application')
> worddoc = wordapp.Documents.Open(mypathfile)
> print(wordapp.ActivePrinter)
> "\\server\queries"
> wordapp.ActivePrinter = "\\server\letters" //fails on this line
> 
> 
>   File "C:\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 544, in __setattr__
>     self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'There is a printer error.', 'wdmain11.
> chm', 24696, -2146823072), None)
> 
> If I don't try to change printers - it prints too the default printer.
> 
> Cheers
> 
> Colin

\\\\server\\letters - the extra back slashes were required.

Colin



More information about the Python-list mailing list