Sign in to follow this  
Followers 0
boogieoompa

Embeded Word Document

6 posts in this topic

I am writting a script that will eventually read a file for all word documents, populate them in a list and allow a user to edit them and eventually sign them (which will generate a pdf). The problem is I do not seem to be able to control the embeded word document via autoit, which is weird because if it weren't embeded I would have no problem. The issue here lies in FunApprove where I try to send an "s" (eventually ctrl s but I wasnt sure if the ctrl was throwing it off). When I click the approve button it just hangs.

Any suggestions would be greatly appreciated.

thanks

#include <IE.au3>
#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>
#Include <GUIComboBox.au3>

_IEErrorHandlerRegister ()
opt("GUIOnEventMode", 1)


$oIE = _IECreateEmbedded()
;change location to network and dr to blank
$location = "C:\project\Autoit\wordreader"
$file = ""

;Authentication part... to be added later
;$authentication = GUICreate("Log In",300,100,300,300)
;$ok = GUICtrlCreateButton("OK",1,1,20,20)
;GUICtrlSetOnEvent($ok, "FunEnable")
;WinActivate("Log In")
;GUISetOnEvent($GUI_EVENT_CLOSE, "FunClose")
;GUISetState()

$maingui = GUICreate("GUI", 1280, 800, 1, 1)
$activex = GUICtrlCreateObj($oIE, 250, 40, 1000, 700)
$btnapprove = GUICtrlCreateButton("Approve", 250, 10, 80, 25)
$btnreject = GUICtrlCreateButton("Reject", 350, 10, 80, 25)
$btnprev = GUICtrlCreateButton("Previous", 450, 10, 80, 25)
$btnnext = GUICtrlCreateButton("Next", 550, 10, 80, 25)
$lstmain = GUICtrlCreateList("",10,40,220,700)
GUICtrlSetOnEvent($lstmain,"FunListSelect")
GUICtrlSetOnEvent($btnapprove,"FunApprove")


GUISetOnEvent($GUI_EVENT_CLOSE, "FunClose")

FunEnable() ;turn off
FunRead()
While 1
    sleep(100)
WEnd

_IENavigate ($oIE, "about:blank")
$oDoc = 0
$oWord = 0

Func FunApprove()
    GUICtrlSetState($activex, $GUI_FOCUS)
    Send("s")
EndFunc

Func FunEnable()
;   GUIDelete($authentication)
    GUISetState()
EndFunc

Func FunListSelect()
    FunLoad(GUICtrlRead($lstmain))
;   MsgBox(0,"Selected",GUICtrlRead($lstmain))
EndFunc



Func FunRead()
        $FileList=_FileListToArray($location, "*.doc")
        If @Error=1 Then
        MsgBox (0,"","No Folders Found.")
        Exit
    EndIf
    If @Error=4 Then
        MsgBox (0,"","No Files Found.")
        Exit
    EndIf
    $max = UBound($FileList)
    $i = 1
    
    While $i < $max
        GUICtrlSetData($lstmain, $filelist[$i])
        $i = $i+1
    WEnd
    If $FileList[0] > 0 Then        
        FunLoad($FileList[1])
    Endif
EndFunc

Func FunLoad($File)
        $sFile = $location & "\" & $file
            If $sFile <> "" Then
                _IENavigate ($oIE, $sFile, 0)
                While $oIE.ReadyState <> 4
                    Sleep(50)
                WEnd
                $oDoc = $oIE.Document
                $oWord = $oDoc.Application
                ; Put document into 'Web View' mode.doc
                $oWord.Activewindow.View = 6
                ; Manage display of toolbars
                $oDoc.CommandBars ("Reviewing").visible = False
                $oDoc.CommandBars ("Standard").Visible = False
            EndIf
EndFunc


Func FunClose()
    Exit
EndFunc

Share this post


Link to post
Share on other sites



Anyone? This seems like its almost a glitch with the Send function since a manual keystroke works. Is there a lower level key command I could send?

Thanks

Share this post


Link to post
Share on other sites

Weird so since I've been playing with this and found that if I call an external autoit program it WILL send to the embeded IE Browser. So it looks like it does accept the Send() function just not from within the program. I tried to explicitly give it focus before the send and still no go. Unless someone has any better ideas at the moment I have to write a seperate .au3 for each send command I want to do, which is a pain since passing variables will be a bit messy.

Share this post


Link to post
Share on other sites

I'm no expert, but am working on a similar project using word docs.

I've found that [using word.au3] I had to add a sleep (200) after a send to Word. It may be that your script sends input faster than the recipient program can deal with.

No science behind this, but perhaps worth a try.

William

Share this post


Link to post
Share on other sites

Thanks for the advice, unfortunatly I tried that with no luck (increased it to a second). I even tried resetting focus to something else and reactivating the window with still no luck. The cursor does stop blinking however when I use the send command... not sure if that means anything.

Share this post


Link to post
Share on other sites

OK so since there seems to be a glitch in the IE embeded object I am now trying to use .exes to fire off commands. The problem is some of them seem to be having trouble sending key strokes to the live window.

This one works

sleep(200)
Send("^s")

This one does not

sleep(250)
Send("^{end}")
Sleep(200)
Send("test fooooter sig")

Ultimatly I should beable to do this within the app itself so preferably if someone could shed some light on what im doing wrong in my main script (below) with regards to embeding browser. Currently a straight send command just stops the cursor from blinking, I have tried setting focus, send and sleep, send.

Thanks

#include <IE.au3>
#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>
#Include <GUIComboBox.au3>

_IEErrorHandlerRegister ()
opt("GUIOnEventMode", 1)


$oIE = _IECreateEmbedded()
;change location to network and dr to blank
$location = "C:\Ben\TMMC\EMR\Autoit\"
$folder = "test1"
$file = ""
$currentindex = 1

;$authentication = GUICreate("Log In",300,100,300,300)
;$ok = GUICtrlCreateButton("OK",1,1,20,20)
;GUICtrlSetOnEvent($ok, "FunEnable")
;WinActivate("Log In")
;GUISetOnEvent($GUI_EVENT_CLOSE, "FunClose")
;GUISetState()

$maingui = GUICreate("Torrance Memorial Radiology Group", 1280, 800, 1, 1)
$activex = GUICtrlCreateObj($oIE, 250, 40, 1000, 700)
$btnapprove = GUICtrlCreateButton("Approve", 250, 10, 80, 25)
$btnreject = GUICtrlCreateButton("Reject", 350, 10, 80, 25)
$btntest = GUICtrlCreateButton("Test", 450, 10, 80, 25)

$lstmain = GUICtrlCreateList("",10,40,220,700)
$lbldr = GUICtrlCreateLabel($folder & " blah", 10,10,200,25)
GUICtrlSetOnEvent($lstmain,"FunListSelect")
GUICtrlSetOnEvent($btnapprove,"FunApprove")
GUICtrlSetOnEvent($btnreject,"FunReject")
GUICtrlSetOnEvent($btntest,"FunTest")


GUISetOnEvent($GUI_EVENT_CLOSE, "FunClose")

FunEnable() ;turn off
FunRead()
While 1
    sleep(100)
WEnd

_IENavigate ($oIE, "about:blank")
$oDoc = 0
$oWord = 0

Func FunTest()
    BlockInput(1)
    run("save.exe")
    sleep(250)
    BlockInput(0)
EndFunc

Func FunEnable()
;   GUIDelete($authentication)
    GUISetState()
EndFunc

Func FunReject()
    FunClear()
    Sleep(500)
    FileMove($location & $folder & "\" & $file, $location & "Rejected\" & $file, 8)
    Sleep(500)
    FunRead()
EndFunc

Func FunClear()
    _IENavigate ($oIE, "C:\Ben\TMMC\EMR\Autoit\splash.html", 0)
    GUICtrlSetData($lstmain, "")
EndFunc

Func FunListSelect()
    $item = GUICtrlRead($lstmain)
    $index = ""
    FunLoad($item)
    $max = UBound($FileList)
    $i = 1
    While $i < $max
        If $FileList[$i] = $item Then
            $index = $i
        EndIf   
        $i = $i + 1
    Wend
EndFunc

Func FunRead()
        Global $FileList=_FileListToArray($location & $folder, "*.doc")
        If @Error=1 Then
        MsgBox (0,"","No Folders Found.")
        Exit
    EndIf
    If @Error=4 Then
        MsgBox (0,"","No Files Found.")
        Exit
    EndIf
    $max = UBound($FileList)
    $i = 1
    
    While $i < $max
        GUICtrlSetData($lstmain, $filelist[$i])
        $i = $i+1
    WEnd
    If $FileList[0] > 0 Then        
        FunLoad($FileList[1])
    Endif
EndFunc

Func FunLoad($tempfile)
        $File = $tempfile
        $sFile = $location & $folder & "\" & $file
            If $sFile <> "" Then
                _IENavigate ($oIE, $sFile, 0)
                While $oIE.ReadyState <> 4
                    Sleep(50)
                WEnd
                $oDoc = $oIE.Document
                $oWord = $oDoc.Application
                ; Put document into 'Web View' mode.doc
                $oWord.Activewindow.View = 6
                ; Manage display of toolbars
                $oDoc.CommandBars ("Reviewing").visible = False
                $oDoc.CommandBars ("Standard").Visible = False
            EndIf
EndFunc

Func FunApprove()
    BlockInput(1)
    run("stamp.exe")
    sleep(250)
    BlockInput(0)
EndFunc

Func FunClose()
    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