Sign in to follow this  
Followers 0
gigi1

Read text from MS Word silently

5 posts in this topic

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

Share this post


Link to post
Share on other sites



You need to be more descriptive on what it is your trying to accomplish.

Share this post


Link to post
Share on other sites

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.

@zedna

thanks for that, i'll try and let you know

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0