[python-win32] OpenDataSource failed inms-word-mail-merge-automation

Hsu. Victor (GSM) victor_hsu at Compalcomm.com
Wed Jan 30 07:04:30 CET 2013


Re-install my Office to English version. Finally know what Word told me.  Let me try how to fix this.

===
F:\MyProgram\python\Word2Email>python Word2Email.py
Traceback (most recent call last):
  File "Word2Email.py", line 41, in <module>
    mm.Execute()
  File "F:\Python27\lib\site-packages\win32com\gen_py\00020905-0000-0000-C000-00
0000000046x0x8x5.py", line 14162, in Execute
    return self._oleobj_.InvokeTypes(105, LCID, 1, (24, 0), ((16396, 17),),Pause

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Word'
, u'Word cannot merge documents that can be distributed by mail or fax without a
 valid mail address. Choose the Setup button to select a mail address data field
.', u'wdmain11.chm', 25110, -2146822658), None)


-----Original Message-----
From: Hsu. Victor (GSM)
Sent: Wednesday, January 30, 2013 11:45 AM
To: 'Tim Roberts'; Python-Win32 List
Subject: RE: [python-win32] OpenDataSource failed inms-word-mail-merge-automation

Hi Tim,

        I fixed it by doing some modification.

data_source_name = os.path.abspath('recipient.csv')
mm.OpenDataSource(data_source_name)

And the "Word Merge To Document" function works now.
However, my intention is to send an email.  So I change some setting,

#send the merge result to Email
mm.Destination = win32com.client.constants.wdSendToEmail
#send the merge result to document
#mm.Destination = win32com.client.constants.wdSendToNewDocument
mm.MailSubject = "This is a test mail from Python Win32---"+time.strftime('%Y_%m_%d')

but now, it failed to run again.
==================
F:\MyProgram\python\Word2Email>python Word2Email.py Traceback (most recent call last):
  File "Word2Email.py", line 41, in <module>
    mm.Execute()
  File "F:\Python27\lib\site-packages\win32com\gen_py\00020905-0000-0000-C000-00
0000000046x0x8x5.py", line 14162, in Execute
    return self._oleobj_.InvokeTypes(105, LCID, 1, (24, 0), ((16396, 17),),Pause

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Word'
, u'\u6c92\u6709\u78ba\u5b9a\u5730\u5740\uff0cWord \u7121\u6cd5\u5408\u4f75\u53e
f\u4f9b\u90f5\u5bc4\u6216\u50b3\u771f\u7684\u6587\u4ef6\u3002\u8acb\u9078\u64c7
[\u8a2d\u5b9a] \u6309\u9215\uff0c\u9078\u53d6\u90f5\u5bc4\u5730\u5740\u8cc7\u659
9\u6b04\u4f4d\u3002', u'wdmain11.chm', 25110, -2146822658), None)


Best Regards,
Victor

-----Original Message-----
From: python-win32 [mailto:python-win32-bounces+victor_hsu=compalcomm.com at python.org] On Behalf Of Tim Roberts
Sent: Wednesday, January 30, 2013 2:00 AM
To: Python-Win32 List
Subject: Re: [python-win32] OpenDataSource failed inms-word-mail-merge-automation

Hsu. Victor (GSM) wrote:
>
>
>         I am trying to use this python sample code to create automatic
> daily report.
>
> http://bytes.com/topic/python/answers/165364-ms-word-mail-merge-automa
> tion
>
>
>
> but I always failed to open the data source in CSV file. Is this
> python issue or Windows COM version issue?
>
> Anyone knows this?
>
>
>
> F:\pythonprogram>python WordEmail.py
>
> Traceback (most recent call last):
>
>   File "WordEmail.py", line 17, in <module>
>
>     mm.OpenDataSource(data_source_name)
>
>   File
> "C:\Users\VICTOR~1\AppData\Local\Temp\gen_py\2.7\00020905-0000-0000-C0
> 00-
>
> 000000000046x0x8x5\MailMerge.py", line 65, in OpenDataSource
>
>     , Connection, SQLStatement, SQLStatement1, OpenExclusive, SubType
>
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
> u'Microsoft Word'
>
> , u'\u627e\u4e0d\u5230\u6a94\u6848\u3002\r (F:\\Google
> \u96f2\u7aef\u786c\u789f\
>
> \...\\\receipent.csv)', u'wdmain11.chm', 24654, -2146823114), None)
>

-2146823114 in hex is 800A1436, which is "this file could not be found".

I see that you have misspelled "recipient".  Could that be the root cause?

--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
This message may contain information which is private, privileged or confidential of Compal Communications, Inc. If you are not the intended recipient of this message, please notify the sender and destroy/delete the message. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information, by persons or entities other than the intended recipient is prohibited.

CCI 2013


More information about the python-win32 mailing list