Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Detecting Word's Invalid Merge Field message from VFP
Message
De
03/04/2007 08:24:11
Loraine Spaeth
Housing Data Systems, Inc.
Wisconsin, États-Unis
 
 
À
02/04/2007 19:16:21
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01211485
Message ID:
01211607
Vues:
25
>>Can anyone tell me how I can detect messages issued by MS Word when automating a mailmerge from my VFP application?
>>
>>I make the Word application invisible while doing the mailmerge and everything works great... usually. The hitch is that we allow our clients to modify the Word documents and sometimes they change or insert a mergefield that is not in the datasource. When this happens, Word issues an "Invalid Merge Field" message and waits for user interaction to resolve any field conflicts. Since we make Word invisible until the merge is all completed, the message gets hidden behind our application and the application appears to be hanging. No one can see that Word has issued a message that requires a response before the next line of code will run. Does anyone know how I can, from VFP, detect that Word has issued a message and either respond to it programmatically or make Word visible so the error can be resolved?
>>
>>Here is a (condensed) description of the code:
>>
>>* Already created the object ref to Word.application and opened my document
>>
>>SELECT (cDataSrcAlias)
>>
>>COPY TO (cTxtFilename) TYPE CSV
>>
>>loMailMerge = oWordApp.activedocument.mailmerge
>>
>>IF nWordVersion < 10
>> loMailMerge.opendatasource(cTxtFilename,4,0,0,0,0,"","",0,"","",,)
>>ELSE
>> * Word XP/10 has additional parameters at the end (last is wdMergeSubtypeWord2000=8)
>> loMailMerge.opendatasource(cTxtFilename,4,0,0,0,0,"","",0,"","",,,"",0,8)
>>ENDIF
>>
>>loMailMerge.Destination = 0 && 0=SendToNewDocument 'Form Letter1'
>>
>>loMailMerge.Execute && Run the mailmerge
>>
>>* AT THIS POINT WORD MAY HAVE ISSUED THE 'INVALID MERGE FIELD' MESSAGE AND IS WAITING...
>>* IF I DO AN ALT-TAB TO GET TO THE MESSAGE WINDOW AND RESOLVE THE MERGEFIELD ERRORS, THEN
>>* PROCESSING CONTINUES, OTHERWISE IT HALTS UNTIL SOMEONE DOES AN ENDTASK ON THE APPLICATION.
>>
>>* I SOMETIMES INSERT TABLES/RECORDSETS AT THIS POINT IN CODE, DEPENDING ON THE LETTER, AND
>>* I DON'T WANT THE USER TO SEE THIS UNTIL I AM ALL DONE; THEN I MAKE WORD VISIBLE.
>>
>>oWordapp.Activate()
>>oWordApp.WindowState = 1 && wdWindowStateMaximize
>>
>>Can you help me to detect and handle the Word message?
>>Thanks!
>>
>>Loraine
>
>Loraine,
>Before merging you can check list of mergefields against your merge fields.
>Cetin


Hi Cetin,

I could do that but really didn't want to because our application generates a lot of mailmerge output and I didn't want to add that overhead when the error situation happens infrequently.

Any other ideas?
Thanks,
Loraine
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform