gigi1 Posted December 15, 2010 Share Posted December 15, 2010 hi, i've searched a lot for a solution to this, but i cant find out. here's my problem: i need to read text from a WinWord window silently. i cannot use _WordDocSaveAs because it changes the window title after saving, i cannot select/copy the text because this is visible, too. here's my code, but it misses the main part #include <Word.au3> HotKeySet("{ESC}", "EsciProgramma") Global $Folder=@ScriptDir Opt("WinTitleMatchMode", 2) MsgBox(0, "WinWordCopy", "Press ESC to exit") _WordErrorHandlerRegister() While 1 If ProcessExists("winword.exe") Then $WinList = WinList("Microsoft Word") For $i=1 To $WinList[0][0] Step 1 ;just in the case of multiple winword windows running If WinActive($WinList[$i][0]) Then $oWord = ObjGet("","Word.Application") $oDocument = _WordDocGetCollection($oWord, 0) ;??? EndIf Next EndIf Sleep(2000) WEnd Func EsciProgramma() Exit EndFunc thanks in advance Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted December 15, 2010 Moderators Share Posted December 15, 2010 You need to be more descriptive on what it is your trying to accomplish. Link to comment Share on other sites More sharing options...
Zedna Posted December 15, 2010 Share Posted December 15, 2010 Probably something like this: #include <Word.au3> $oWordApp = _WordCreate (@ScriptDir & "\Test.doc", 0, 0) $oDoc = _WordDocGetCollection ($oWordApp, 0) $oDoc.Range.WholeStory() $oDoc.Range.Copy() ; to ClipBoard ; $text = $oDoc.Range.Text Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
gigi1 Posted December 16, 2010 Author Share Posted December 16, 2010 You need to be more descriptive on what it is your trying to accomplish.i'm trying to write a program that silently recognize when ms word is open and active (got this part), read text and save to file. i have problems with reading from ms word without being noticed.@zednathanks for that, i'll try and let you know Link to comment Share on other sites More sharing options...
gigi1 Posted December 16, 2010 Author Share Posted December 16, 2010 ok, i got it! thanks zedna for your help. this is the final code, if someone is interested #include <word.au3> HotKeySet("{ESC}", "EsciProgramma") Opt("WinTitleMatchMode", 2) MsgBox(0, "WinWordCopy", "Press ESC to exit") _WordErrorHandlerRegister() While 1 If ProcessExists("winword.exe") Then $WinList = WinList("Microsoft Word") For $i=1 To $WinList[0][0] Step 1 If WinActive($WinList[$i][0]) Then $oWord = ObjGet("","Word.Application") ;gets the object of the word application $oDoc = _WordDocGetCollection($oWord, 0) ;gets the object of the current active document $oDoc.Range.WholeStory() ;range -> wholestory $text = $oDoc.Range.Text ;read the text ConsoleWrite($text&@CR) ;writes text to console EndIf Next EndIf Sleep(2500) WEnd Func EsciProgramma() Exit EndFunc 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