NutCracker Posted May 4, 2011 Share 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 Link to comment Share on other sites More sharing options...
Juvigy Posted May 4, 2011 Share Posted May 4, 2011 Dont use _WordQuit , use _WordDocClose instead. Link to comment Share on other sites More sharing options...
NutCracker Posted May 4, 2011 Author Share 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) Link to comment Share on other sites More sharing options...
Juvigy Posted May 4, 2011 Share 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. Link to comment Share on other sites More sharing options...
phoenix73 Posted July 27, 2011 Share 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! Link to comment Share on other sites More sharing options...
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