Hey Everyone,
I've recently started using AutoIt to speed up my work a bit and ran into a snag..
On my development PC, I've made a small GUI application which opens an .xls file to get part of it's input. Now the funny thing is that it runs great on that pc (no problems, everything works as it was written) but when I compile the script and try to run it onto any other machine, it will fail to open any .xls(x) file and gets thrown out with an @error 2.
It does not seem to be OS related as I tried different configurations. I have tried the Beta Includes but to no avail.
Can anyone help me?
This is the function where it goes wrong:
All elements passed to it checked out okay, it seems to me that something happends in the _ExcelBookOpen code.
Func OpenTestPlan(ByRef $oExcel, ByRef $TestPlanOpen, $Action, ByRef $AutomationTestColumn)
switch $Action
Case "Close"
if $TestPlanOpen = True Then
_ExcelBookClose($oExcel)
$TestPlanOpen = False
GUICtrlSetData($EditTestCase, "")
GUICtrlSetData($EditResult, "")
GUICtrlSetData($EditComment, "")
GUICtrlSetData($EditBug, "")
$AutomationTestColumn = "No"
EndIf
Case "Open"
If $TestPlanOpen = False Then
#Region : Variable Declaration
Local $WorkingDir
Local $FileName
Local $Path
Local $Worksheet
#EndRegion : Variable Declaration
#Region : Function Logic
$WorkingDir = FileSelectFolder("In which folder is your testplan located?","c",2) ; Get the folder where the File is located
Switch @error
case 1
$WorkingDir = ""
MsgBox(64,"Cancel Pressed","No testplan opened")
case Else
ListSelectionGUI("Select your testplan", "Click Here", _FileListToArray($WorkingDir), $FileName) ; Select the .xls testplan we are going to work on
if $FileName <> "Click Here" then
$oExcel = _ExcelBookOpen($WorkingDir & "\" & $FileName,1) ; Open an existing workbook (visible) and returns its object identifier. !!!!!Modify mode!!!!!!
Switch @error
case 1
MsgBox(16, "Error!", "Unable to Create the Excel Object")
Msgbox(46,"Debug Info", "Path Directory : " & $WorkingDir & "\" & $FileName)
Exit
case 2
MsgBox(16, "Error!", "The file does not exist")
EndSwitch
$TestPlanOpen = True
ListSelectionGUI("Select the worksheet to be executed","Click Here", _ExcelSheetList($oExcel), $Worksheet) ; Select the worksheet to be tested
if $Worksheet <> "Click Here" Then
_ExcelSheetActivate($oExcel, $Worksheet) ; Activate the selected worksheet
GUICtrlSetData($EditComment,"Now start the process by clicking the <Next> button below!")
$AutomationTestColumn = (-64 + Asc ( InputBox("Automation Input","Which column contains the Automation Scripts?","No")))
Switch @error
case 1 ; Cancel pressed
$AutomationTestColumn = ""
MsgBox(64,"Cancel Pressed","No Automation column selected")
EndSwitch
Else
_ExcelBookClose($oExcel)
EndIf
EndIf
EndSwitch
Else
MsgBox(16, "Warning", "A Testplan is still open, please close it first!")
EndIf
#EndRegion : Function Logic
EndSwitch
EndFunc
This is the _ExcelBookOpen code which is called:
Func _ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False, $sPassword = "", $sWritePassword = "")
Local $oExcel = ObjCreate("Excel.Application")
If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
If $fVisible > 1 Then $fVisible = 1
If $fVisible < 0 Then $fVisible = 0
If $fReadOnly > 1 Then $fReadOnly = 1
If $fReadOnly < 0 Then $fReadOnly = 0
With $oExcel
.Visible = $fVisible
If $sPassword <> "" And $sWritePassword <> "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly, Default, $sPassword, $sWritePassword)
If $sPassword = "" And $sWritePassword <> "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly, Default, Default, $sWritePassword)
If $sPassword <> "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly, Default, $sPassword, Default)
If $sPassword = "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly)
; Select the first *visible* worksheet.
For $i = 1 To .ActiveWorkbook.Sheets.Count
If .ActiveWorkbook.Sheets($i).Visible = $xlSheetVisible Then
.ActiveWorkbook.Sheets($i).Select()
ExitLoop
EndIf
Next
EndWith
Return $oExcel
EndFunc ;==>_ExcelBookOpen
Thanks a lot!!
Kris