NutCracker Posted May 4, 2011 Posted May 4, 2011 Hi guys am stuck up at a point, when i save and close a word file all the word files opened get closed. below is the code : $oWordApp = _WordCreate ($wordfile, 1,0) $oDoc = _WordDocGetCollection ($oWordApp, 0) $oRange = $oDoc.Range _WordDocFindReplace($oDoc, $sSearch, "", 0, $oRange) With $oRange ; Insert a new line, updating the range. .insertAfter (@CR) ; Collapse the range to the end point .Collapse ($wdCollapseEnd) EndWith $oShape =_WordDocAddPicture ($oDoc, $file, 0, 1,$oRange) If Not @error Then $oShape.Range.InsertAfter(@CRLF) _WordDocSave ( $oWordApp ) _WordQuit($oWordApp, 0, 1, 0) When i close the word file all other files get automatically closed. What i want is only the created word file should get saved and closed whereas other opened word docs should be untouched. please help me out
NutCracker Posted May 4, 2011 Author Posted May 4, 2011 thanks Juvigy but still not getting what i wanted other word files also get closed: If Not @error Then $oShape.Range.InsertAfter(@CRLF) ;_WordDocSave ( $oDoc ) _WordDocClose ($oDoc,-1) ;_WordQuit($oWordApp, 0, 1, 0)
Juvigy Posted May 4, 2011 Posted May 4, 2011 Check this out: $oWordApp = _WordAttach ("C:\2010.doc") For $element in _WordDocGetCollection ($oWordApp) MsgBox(64, "Document FileName", $element .FullName) _WordDocClose ($element) Exit Next This code will only close 1(first in the collection) of the documents and leave word open.
phoenix73 Posted July 27, 2011 Posted July 27, 2011 Hi all, I had the same problem reported by @shreyash and finally I find this solution that seems to work fine: #include <Word.au3> $myDoc = @ScriptDir & "\Test.doc" $oWordApp = ObjCreate("Word.Application") _WordDocOpen($oWordApp, $myDoc) $oDoc = _WordDocGetCollection ($oWordApp, 0) ; 0 = Returns the Active Document ; work with $oDoc, for instance... $oDoc.Range.insertAfter("Hello world!" & @CR) _WordDocSave($oDoc) For $element in _WordDocGetCollection ($oWordApp) MsgBox(64, "Document FileName", $element .FullName) _WordDocClose($element) ExitLoop Next _WordQuit ($oWordApp) ShellExecute($myDoc) ...and the other opened word docs remain untouched!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now