Jump to content

#include <Excel.au3> Excel AutoIT Bug?


gamarga
 Share

Recommended Posts

Hi,

I am using AutoIT version 3.2.8.1 which initially did not have Excel.au3 in "C:\Program Files\AutoIt3\Include" so I added it manually and the code below works fine for me from script or when compiled. The problem I am having is that when my friend tried it on another PC it gives the error box (See attached):

Line -1:

Error: The requested action with this object has failed.

The weird thing is that when I log into the same machine (we have roaming profiles) it works fine for me. Admin rights are the same locally. Tried it on a third machine and it also worked when compiled.

When trying to run the script from my friends computer uncompiled if seems to fail on line 149 where it tries to open Book1.xls

Why would compiled version work on one persons login and not another? Any help on where im going wrong with this code would be appreciated.

#include <Excel.au3>
#include <Array.au3>

Do
If WinExists("Microsoft Excel - Book1.xls") Then
    ;MsgBox(16, "EXCEL", "Book1.xls is open. Close, save then click ok.")
        WinActivate("Microsoft Excel - Book1.xls")
        Send("^{S}")
        Send("^{F4}")
EndIf
Until WinExists("Microsoft Excel - Book1.xls") = 0


Global $Array[6000] ;Declare an array for technical update to go into

$password = InputBox("Enter logon Password", "Enter password and click OK", "", "*") ;Password to logon to PC.
If @error = 1 Then
    Exit
EndIf

$mintime = InputBox("Time","Enter minimum interval in mins:") ; Minimum time in mins between updates
If @error = 1 Then
    Exit
EndIf

$maxtime = InputBox("Time","Enter maximum interval in mins:") ; Maximum time in mins between updates
If @error = 1 Then
    Exit
EndIf

WinMinimizeAll()

Func findtab() ;Function to select the Work Info tab in remedy
    Sleep(3500)
    For $i = 1 to 22        
        sleep(800)
        Send("{TAB}")
        sleep(200)
    Next
    Sleep(1000)
    For $i = 1 to 3 
        sleep(300)                                                      
        Send("{RIGHT}")
    Next
EndFunc

Func workinfotab()
    Sleep(3000)
    For $i = 1 to 3
        sleep(300)
        Send("{TAB}")
    Next
    Sleep(1000)
    For $i = 1 to 7
        sleep(300)
        Send("{DOWN}")
    Next
    Send("{TAB}")
EndFunc


Func closenote()
    Do
        If WinExists("Work Info (fms.easynet.com) -- Notes") Then
            WinClose("Work Info (fms.easynet.com) -- Notes")
            Sleep(1000)
        EndIf
        Sleep(1000)
        If WinExists("Work Info (fms.easynet.com)") Then
            WinClose("Work Info (fms.easynet.com)")
            Sleep(1000)
        EndIf
    Until WinExists("Work Info (fms.easynet.com)") = 0
EndFunc


Func searchwindow()
    Do

        If WinExists("BMC Remedy User - [Home Page (Search)]") Then
            ControlClick("BMC Remedy User - [Home Page (Search)]", "","[CLASS:Internet Explorer_Server; INSTANCE:1]",  "left", 1,  66, 279)
        EndIf
        Sleep(1000)
        If WinExists("BMC Remedy User - [Incidents (Search)]") Then
            WinActivate("BMC Remedy User - [Incidents (Search)]")
            Send("^{F4}")
        EndIf
        Sleep(1000)
        If WinExists("BMC Remedy User - [Incident (Modify)]") Then
            WinActivate("BMC Remedy User - [Incident (Modify)]")
            Send("^{F4}")
        EndIf
        Sleep(1000)
    Until WinExists("BMC Remedy User - [Incident Management Console (Search)]")
    If WinExists("BMC Remedy User - [Home Page (Search)]") Then
       ControlClick("BMC Remedy User - [Home Page (Search)]", "","[CLASS:Internet Explorer_Server; INSTANCE:1]",  "left", 1,  66, 279)
    EndIf
EndFunc
    

Func consolview()
    Do
        If WinExists("My Group Selection (fms.easynet.com)") Then 
            WinActivate("My Group Selection (fms.easynet.com)")
            Sleep(1000)
            Send("^{F4}")
            Sleep(2000)
            ControlClick("BMC Remedy User - [Incident Management Console (Search)]", "","[CLASS:Internet Explorer_Server; INSTANCE:1]",  "left", 1,  61, 12)
        EndIf
        Sleep(1000)
        If WinExists("BMC Remedy User - [Incident Management Console (Search)]") Then
            WinActivate("BMC Remedy User - [Incident Management Console (Search)]")
            Sleep(2000)
            ControlClick("BMC Remedy User - [Incident Management Console (Search)]", "","[CLASS:Internet Explorer_Server; INSTANCE:1]",  "left", 1,  61, 12)
            Sleep(2000)
            ControlClick("BMC Remedy User - [Incident Management Console (Search)]", "","[CLASS:Internet Explorer_Server; INSTANCE:1]",  "left", 3,  53, 91)
        EndIf

    Until WinExists("BMC Remedy User - [Incidents (Search)]")
EndFunc
    



Run ("rundll32.exe user32.dll,LockWorkStation") ; Lock the Desktop for 5 second and logback on. This tests logon password is correct.
Sleep(5000)
run ("Logon.exe -p " & $password)
Sleep(2000)






$i = 0
Do
    
    run ("Logon.exe -p " & $password)
    
    Sleep(2000)
    
    $time = Random($mintime,$maxtime, 1) ;Chooses random time between min & max time between updates
    
    $time = $time * 1000 * 60 ; Converts random chosen time to miliseconds

    $time = Round($time) ;Changes random chosen time in milisends to a round number


    Global $oExcel = _ExcelBookOpen("Book1.xls", 0);Read excel spreadsheet, 0 for invisible.
    
    $sCellValue = _ExcelReadCell($oExcel, 1, 1) ; Read cell 1, 1 (Column A, Row 1) to variable
    
    $result = StringAddCR($sCellValue) ;Split string to remove carriage return and place into variabe $result
    ClipPut($result) ; Copy $result to clipboard
    
    closenote()
    searchwindow()
    
    
    If $result = ("") Then
        MsgBox(64, "FINISHED", "No more text in spreadsheet." & @CRLF & "EXITING...")
        ExitLoop
    EndIf

    WinWait("BMC Remedy User - [Incident Management Console (Search)]")
    ControlClick("BMC Remedy User - [Incident Management Console (Search)]", "","[CLASS:Internet Explorer_Server; INSTANCE:1]",  "left", 3,  53, 91) ; Click Remedy search button
    Sleep(2000)
    
    consolview()
    

    WinWait("BMC Remedy User - [Incidents (Search)]")
    
    WinMove("BMC Remedy User - [Incidents (Search)]", "", 67, 75, 1179, 859) 

    sleep(2000)

    ControlSend("BMC Remedy User - [Incidents (Search)]", "", "[CLASS:RichEdit20A; INSTANCE:1]", $result) ; Paste $result (Ticket number) into search box
    Sleep(750)
    ControlSend("BMC Remedy User - [Incidents (Search)]", "", "[CLASS:RichEdit20A; INSTANCE:1]", "{F5}" ) ;Search for ticket
    WinWait("BMC Remedy User - [Incident (Modify)]") ;Wait until window exsists
    WinActivate("BMC Remedy User - [Incident (Modify)]") ;Activate remedy window
    Sleep(4000)
    findtab() ;Call to findtab function
    Sleep(1500)
    workinfotab() ;Call to workinfo function
    Sleep(1500)
    
    $sCellValue = _ExcelReadCell($oExcel, 1, 3) ;Read cell 1, 3 (Column C, Row 1) to variable
    $result = StringAddCR($sCellValue) ;Adds carriage returns from cell to CR points in text 
    $Array = StringSplit($sCellValue, @CRLF ) ;Adds the excel cell to variable $Array splitting up the lines of text
    $Line1 = $Array[1] ;Adds line 1 of array to variable $Line1
    $Line2 = $Array[2] ;Adds line 2 of array to variable $Line2
        
    ClipPut($line1 & @CRLF & $line2) ;Adds variables ($lines1 and $lines2 of array) to clipboard with carriage return in between
    Send("^v") ;Paste
    Sleep(750)
    Send("{TAB}")
    Sleep(750)
    ClipPut($result) 
    Send("^v")
    Sleep(750)  
    
    Send("^{ENTER}") ;Save
    Sleep(1000)
    Send("^{F4}") ; Close ticket
    
    _ExcelRowDelete($oExcel, 1, 1) ;Delete row 1 and only 1 row
    Sleep(750)
    _ExcelBookClose($oExcel, 1, 0) ; Close spreadsheet
    FileClose($oExcel)
    Sleep(750)
    


    sleep (3000)
    Run ("rundll32.exe user32.dll,LockWorkStation") ; Lock the Desktop

    sleep ($time)
    run ("c:\Logon.exe -p " & $password) ;Unlock desktop
    Sleep(5000)

    $i = $i + 1
Until $i = 1000

Do
$wingetstate = WinGetState("Microsoft Excel - Book1.xls")
$PID = ProcessExists("EXCEL.EXE")
    If $PID & WinExists("Microsoft Excel - Book1.xls") & $wingetstate = 2 Then
        Sleep(100)
    Else
        ;WinKill("Microsoft Excel - Book1.xls")
        ProcessClose("EXCEL.EXE")
    EndIf
Until $PID = 0

;Next

untitled.bmp

Link to comment
Share on other sites

Where is the problem to update to version >= 3.3.0.0.

If then the problem still exists, I will look after your code.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Where is the problem to update to version >= 3.3.0.0.

If then the problem still exists, I will look after your code.

thanks funkey

I am the friend mentioned in the original post.

I have uninstalled all autoit software, reinstalled 3.3.0.0, re-compliled the code using 3.3.0.0, as you advised...

but i still have the same error.

Any ideas?

Link to comment
Share on other sites

For me it works. I don't know what 's wrong. Just try following code to figure out, that this part is the problem. If it is the problem, then it looks like you have trouble with Excel.

btw: you open the excebook every loop and you never close it. Just open it once before the loop.

#include <Excel.au3>
$oExcel = _ExcelBookOpen("Book1.xls", 0);Read excel spreadsheet, 0 for invisible.
If @error Then  MsgBox(0,"", @error)
$sCellValue = _ExcelReadCell($oExcel, 1, 1) ; Read cell 1, 1 (Column A, Row 1) to variable

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Hey,

Thanks for your response funkey :)

On line 210 in the loop it closes the spreadsheet.

I have have sort of solved it. When I added the If @error code below after trying to open the book it failed with error 2 so I need to put the full path of the Excel spreadsheet. For some reason on matey boys computer that fails even tho all the files are in the same directory. It still does not explain why I dont have to do that for my profile and matey boy has to put in full path of Book1.xls.

Edit: Also checked Excel version and they are exactly the same....

Global $oExcel = _ExcelBookOpen(@ScriptFullPath & "Book1.xls", 0);Read excel spreadsheet, 0 for invisible.

   If @error = 1 Then
            MsgBox(0, "Error!", "Unable to Create the Excel Object")
            Exit
        ElseIf @error = 2 Then
            MsgBox(0, "Error!", "File does not exist - Shame on you!")
            Exit
        EndIf
Edited by gamarga
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...