Hi everybody,
I'm using a MS Word 2003-Automation to pass certain values from a textfile into a document (mail merge). In some cases I receive the error message
"The type 'Automation' was not defined for the function"
After a very long series of testing (which is very difficult because the error does not always rise up and everything works on other machines) I found out that apparently it takes to long to either create the application or the document instance. Below you find my C/AL-code. If the debugger is active, it stops at the line "wdDocument := wdDocuments.Add(l_txtPath)". For me it seems as if MS Word is - at that moment - not yet ready to receive the 'input' comming from the mail merge file.
So that brings me to the following question: Is there an object/method available to request the state of Word? Somehting like
"IF (wdApp.active = true) then...."
I don't want to use a "SLEEP" because that is "dirty" and just a workaround. It would also make the application-load-process sleeping and after the sleep may cause the same problem.
CREATE(wdApp);
l_recDocumenttemplate.GET(p_Schriftverkehr.Dokumentvorlage);
l_recDocumenttemplate.TestTemplate;
l_txtPath := l_recDocumenttemplate.Path;
//--------------------------------------------------------------------------------------------------------------------//
//--- Create an Instance ---//
//--------------------------------------------------------------------------------------------------------------------//
wdDocuments := wdApp.Documents;
//--------------------------------------------------------------------------------------------------------------------//
//--- Add, to create an new empty document at the specified Path ---//
//--------------------------------------------------------------------------------------------------------------------//
wdDocument := wdDocuments.Add(l_txtPath); //
MergeFileName := PathTxt;
Thanks in advance for your help.
Regards,
Jonny
Comments
first of all: Thanks for your help!
We've done some more testing and analysis and have come to the conclusion that the issue is less related to the loading-time but is directly connected to the changed settings of the document template folder. Both customers have changed this setting in Word from the default folder (AppData\Roaming\Microsoft\Templates) to a folder on a network share. This caused the problems. Whenever the "normal.dotm" is located in a local drive everything is ok -but as soon as it's not local the problem rises up. So it's more an infrastructural then an application issue.
Maybe that helps if of you one day faces a similar issue.
I wish you all a merry Christmas!
Regards,
Jonny