AvidLearner Posted March 16, 2009 Share Posted March 16, 2009 (edited) CODE#include<word.au3> $oWordApp = _WordAttach ($docname, "FileName") $oDoc = _WordDocGetCollection ($oWordApp, 0) $oPath = $oDoc.FullName msgbox(0,$oPath,"") $docname is known which will be a open document.... I get an error msg saying " Variable must be of type Object " I tried and could not get the full path of the document.. Plz do help.. Thanx... Edited March 16, 2009 by AvidLearner Link to comment Share on other sites More sharing options...
foster74 Posted March 17, 2009 Share Posted March 17, 2009 The 0 in the line "_WordDocGetCollection ($oWordApp, 0)" returns the active document, so the following will work: #include<word.au3> $oWordApp = _WordAttach ($docname, "FileName") WinActivate ($docname) WinWaitActive($docname) $oDoc = _WordDocGetCollection ($oWordApp, 0) $oPath = $oDoc.FullName msgbox(0,$oPath,"") I'd imagine there are better ways to get the full path though. Link to comment Share on other sites More sharing options...
AvidLearner Posted March 17, 2009 Author Share Posted March 17, 2009 The 0 in the line "_WordDocGetCollection ($oWordApp, 0)" returns the active document, so the following will work: #include<word.au3> $oWordApp = _WordAttach ($docname, "FileName") WinActivate ($docname) WinWaitActive($docname) $oDoc = _WordDocGetCollection ($oWordApp, 0) $oPath = $oDoc.FullName msgbox(0,$oPath,"") I'd imagine there are better ways to get the full path though. Thank you foster74... Yeah I tried it... but m getting an error saying " Variable must be of type Object " Could you plz show me an easier way to get d path... Thnx in advance... Link to comment Share on other sites More sharing options...
foster74 Posted March 17, 2009 Share Posted March 17, 2009 Tell me what errors are showing. #include<word.au3> $oWordApp = _WordAttach ($docname, "FileName") ConsoleWrite('_WordAttach Error = ' & @ERROR & @CRLF) WinActivate ($docname) WinWaitActive($docname) $oDoc = _WordDocGetCollection ($oWordApp, 0) ConsoleWrite('_WordDocGetCollection Error = ' & @ERROR & @CRLF) $oPath = $oDoc.FullName msgbox(0,$oPath,"") Link to comment Share on other sites More sharing options...
AvidLearner Posted March 17, 2009 Author Share Posted March 17, 2009 Tell me what errors are showing. #include<word.au3> $oWordApp = _WordAttach ($docname, "FileName") ConsoleWrite('_WordAttach Error = ' & @ERROR & @CRLF) WinActivate ($docname) WinWaitActive($docname) $oDoc = _WordDocGetCollection ($oWordApp, 0) ConsoleWrite('_WordDocGetCollection Error = ' & @ERROR & @CRLF) $oPath = $oDoc.FullName msgbox(0,$oPath,"") I got $oPath = 0 from MsgBox command Earlier I got errors saying line : -1 Error:variable must be of type object Link to comment Share on other sites More sharing options...
foster74 Posted March 17, 2009 Share Posted March 17, 2009 Run the following code: #include<word.au3> $oWordApp = _WordAttach ($docname, "FileName") msgbox(0,'','_WordAttach Error = ' & @ERROR & @CRLF) WinActivate ($docname) WinWaitActive($docname) $oDoc = _WordDocGetCollection ($oWordApp, 0) msgbox(0,'','_WordDocGetCollection Error = ' & @ERROR & @CRLF) $oPath = $oDoc.FullName msgbox(0,$oPath,"") And tell me what the first two message boxes say. Link to comment Share on other sites More sharing options...
AvidLearner Posted March 17, 2009 Author Share Posted March 17, 2009 Run the following code: #include<word.au3> $oWordApp = _WordAttach ($docname, "FileName") msgbox(0,'','_WordAttach Error = ' & @ERROR & @CRLF) WinActivate ($docname) WinWaitActive($docname) $oDoc = _WordDocGetCollection ($oWordApp, 0) msgbox(0,'','_WordDocGetCollection Error = ' & @ERROR & @CRLF) $oPath = $oDoc.FullName msgbox(0,$oPath,"") And tell me what the first two message boxes say. I got _wordattach error=7 and _worddocgetcollection error=3 and sorry fr late reply as server wz down... Thank you Link to comment Share on other sites More sharing options...
AvidLearner Posted March 17, 2009 Author Share Posted March 17, 2009 Could you plz help me in finding some other easier and fail proof method to extract its path if possible... Thank you Link to comment Share on other sites More sharing options...
foster74 Posted March 17, 2009 Share Posted March 17, 2009 #include<word.au3> $docname = 'target.docx' $oWordApp = _WordAttach ($docname, "FileName") $oDoc = _WordDocGetCollection ($oWordApp, -1) For $oDoc in $oDoc If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullName Next msgbox(0,'',$oPath) Link to comment Share on other sites More sharing options...
AvidLearner Posted March 17, 2009 Author Share Posted March 17, 2009 #include<word.au3> $docname = 'target.docx' $oWordApp = _WordAttach ($docname, "FileName") $oDoc = _WordDocGetCollection ($oWordApp, -1) For $oDoc in $oDoc If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullName Next msgbox(0,'',$oPath) Thanks a lot foster... Finally it worked... Link to comment Share on other sites More sharing options...
AvidLearner Posted March 17, 2009 Author Share Posted March 17, 2009 CODEWinwaitActive( "- Microsoft Word" )$title1 = WinGetTitle( "Microsoft Word" )$docname = StringTrimRight( $title1 , 17 )$result = StringInStr( $docname , "compatibility" )If $result = 0 ThenElse $docname = StringTrimRight( $docname , 21 )EndIfMsgBox(0,$docname,$docname)$oWordApp = _WordAttach($docname, "FileName")WinActivate ($docname)WinWaitActive($docname)$oDoc = _WordDocGetCollection ($oWordApp, -1) For $oDoc in $oDoc If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullNameNextThis code is properly working and giving me back the path of the opened word docbutwhen you remove the msgbox() code from the program,,, its showing an error sayingAutoIT error:Line : -1error : variable must be of type "object"Can you help me out here plz..Thank you... Link to comment Share on other sites More sharing options...
foster74 Posted March 18, 2009 Share Posted March 18, 2009 This script works fine for me even with no msgbox at the end. #include<word.au3> Opt("WinTitleMatchMode", 2) WinwaitActive( "- Microsoft Word" ) $title1 = WinGetTitle( "Microsoft Word" ) $docname = StringTrimRight( $title1 , 17 ) $result = StringInStr( $docname , "compatibility" ) If $result <> 0 Then $docname = StringTrimRight( $docname , 21 ) $oWordApp = _WordAttach($docname, "FileName") $oDoc = _WordDocGetCollection ($oWordApp, -1) For $oDoc in $oDoc If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullName Next MsgBox(0,$oPath,$oPath) Link to comment Share on other sites More sharing options...
AvidLearner Posted March 18, 2009 Author Share Posted March 18, 2009 (edited) This script works fine for me even with no msgbox at the end. #include<word.au3> Opt("WinTitleMatchMode", 2) WinwaitActive( "- Microsoft Word" ) $title1 = WinGetTitle( "Microsoft Word" ) $docname = StringTrimRight( $title1 , 17 ) $result = StringInStr( $docname , "compatibility" ) If $result <> 0 Then $docname = StringTrimRight( $docname , 21 ) $oWordApp = _WordAttach($docname, "FileName") $oDoc = _WordDocGetCollection ($oWordApp, -1) For $oDoc in $oDoc If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullName Next MsgBox(0,$oPath,$oPath) yeah ,, It definitely needs an output @ the end... But it isn't working fr me,, its showing error as stated above only when I remove the MsgBox which is highlighted in the abv code box given by me... Is thr any problem wid ma OS or autoIT version...?? m using tthe latest Autoit v3 version,,, Edited March 18, 2009 by AvidLearner 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