I'm developing a document control application. Documents are written with MS Word. Stamping the document control number (DCN) into the Word document footer is a central need. I am placing the DCN onto the clipboard (clipboard_set_data()), opening Word and trying to run a Word macro that pastes the clipboard content into the document footer. The first time it attempts this, it generates the OLE error in the attached screenshot, and leaves WINWORD.EXE as an open windows process. Deleting the WINWORD.EXE from Windows task manager clears this, and from then on, the script runs without errors. Close A5 app, reopen the app and try it again, first time failure, clear the residual WINWORD.EXE from task manager and from then it works OK. What do I need to do to get this to work the first and every time? I've tried pausing things between the commands with xbasic_wait_for_idle(), sleep(), etc, with no joy. I need help, please.
Code:
' generate the file address dim vdoc_file as C vdoc_file=alltrim(vg_doc_template_path)+"test.doc" ' generate the footer and attach to the clipboard dim shared vfooter_text as C vfooter_text="This is footer text for the document for testing" :clipboard.set_data(vfooter_text) ' place the Word macro name (doc_footer_stamp) into a variable dim vword_macro as C="doc_footer_stamp" ' open the word application hidden (windowstate=0) calling the document by the above variable on error goto error_handler Dim wordApp As p wordApp = ole.Create("Word.Application") wordApp.WindowState = 0 wordApp.Documents.Open(vdoc_file) ' stamp document info into footer wordApp.run(vword_macro) [COLOR="Red"]<<< error spot[/COLOR] wordApp.ActiveDocument.SaveAs(vdoc_file) wordApp.quit() GOTO TERMINAL 'error handler error_handler: dim vstamp_error as C err = error_code_get() vstamp_error= error_text_get(err) ON ERROR RESUME 0 msgbox("Error Report",vstamp_error) end TERMINAL:
Comment