I am writing a dxl script to run in batch mode. The purpose of this script is to traverse a Project, find a particular module, export it into MS Word 2007 and then automate the "SaveAs" function within Word 2007 to save the module as a Word file to the file system. I have completed everything successfully, with the exception of the automated "SaveAs" function. I need a function that completes this task. Below is what I have written. |
Re: How to use OLE Automation to save a Word 2007 document to the file system |
Re: How to use OLE Automation to save a Word 2007 document to the file system clear objArgBlock put(objArgBlock, directoryLocation) oleMethod(objWord, "ChangeFileOpenDirectory", objArgBlock) clear objArgBlock put(objArgBlock, fileName) put(objArgBlock, 0) //0 = wdFormatDocument (which is presumably .doc or Word 2003 format) oleMethod(objDoc, "SaveAs", objArgBlock) I've written a wrapper function for my ole commands (not shown here) which just prints out any error message if an OLE command fails, you may want to do something similar instead of the specific check on "result" that you are making. I think DOORS has a checkResult() function which does something similar, but I'm not a fan of theirs. Mine looks like this: TryOLE(string s, string info) { if(s == null) return print info "\n" print s } That allows you to call an ole command like this: TryOLE(oleMethod(objDoc, "SaveAs", objArgBlock), "Attempting to save the document.") That way the ole command is self-documenting and if it fails, you have a very descriptive error message for exactly which ole command failed on you. |
Re: How to use OLE Automation to save a Word 2007 document to the file system Zetareticuli - Wed Jan 05 13:15:08 EST 2011 Have you gotten yours to work. I tried your suggested solution with the same results as my initial post. Any insite and/or advice would be greatly appreciated. Thank you. |
Re: How to use OLE Automation to save a Word 2007 document to the file system
The following works for me: OleAutoObj wDocs = null, wDoc = null OleAutoObj wApp = oleGetAutoObject "Word.Application" olePut (wApp, "visible", "true") oleGet(wApp, "Documents", wDocs) OleAutoArgs args = create() oleMethod (wDocs, "Add", args, wDoc) put (args, "C:\\Temp\\Test.docx") // choose a meaningful file path print "SaveAs:" oleMethod (wDoc, "SaveAs", args)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: How to use OLE Automation to save a Word 2007 document to the file system Mathias Mamsch - Thu Jan 06 17:22:43 EST 2011
The following works for me: OleAutoObj wDocs = null, wDoc = null OleAutoObj wApp = oleGetAutoObject "Word.Application" olePut (wApp, "visible", "true") oleGet(wApp, "Documents", wDocs) OleAutoArgs args = create() oleMethod (wDocs, "Add", args, wDoc) put (args, "C:\\Temp\\Test.docx") // choose a meaningful file path print "SaveAs:" oleMethod (wDoc, "SaveAs", args)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
I thank you greatly for your last post. I had to do a minor tweek to get it to work in my senario. Thank you again. |
Re: How to use OLE Automation to save a Word 2007 document to the file system Mathias Mamsch - Thu Jan 06 17:22:43 EST 2011
The following works for me: OleAutoObj wDocs = null, wDoc = null OleAutoObj wApp = oleGetAutoObject "Word.Application" olePut (wApp, "visible", "true") oleGet(wApp, "Documents", wDocs) OleAutoArgs args = create() oleMethod (wDocs, "Add", args, wDoc) put (args, "C:\\Temp\\Test.docx") // choose a meaningful file path print "SaveAs:" oleMethod (wDoc, "SaveAs", args)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Hi Mathias,
I'm hoping if I write here that you'll get an update or something. I tried following what you instructed above, but Doors just saves a blank word document and the exported document is left unsaved. I posted a question here and included the code that I am using:
If you have any insight or advice, I would greatly appreciate it. |