Jump to content
Sign in to follow this  
Mecrazycoder

Unable to open Excel file?

Recommended Posts

Mecrazycoder

Hi Guys,

I wrote a script to open Excel file.

#Include<Excel.au3>

$oExcel=_ExcelBookOpen("TableInput.xls")
$sheetNameList=_ExcelSheetList($oExcel)
For $i=1 To $sheetNameList[0]
    MsgBox(0,"",$sheetNameList[$i])
Next
but the problem when i run it i am getting error as

F:\Tools\AutoIt3\Include\Excel.au3 (189) : ==> The requested action with this object has failed.:

If $sPassword = "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly)

If $sPassword = "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly)^ ERROR

Is there anything wrong with my code.File is not password protected.Tanx in advance Edited by Mecrazycoder

[size="4"][font="Arial Narrow"][font="Garamond"]Attitude is a little thing that makes a big difference[/font][/font][/size][indent][/indent]

Share this post


Link to post
Share on other sites
Juvigy

this line is completely wrong:

For $i=1 To $sheetNameList[0]

change it to:

For $i=0 To Ubound($sheetNameList)-1 step 1

Share this post


Link to post
Share on other sites
Mecrazycoder

this line is completely wrong:

For $i=1 To $sheetNameList[0]

change it to:

For $i=0 To Ubound($sheetNameList)-1 step 1

Tanx man but i am afraid its not working.Any way without loop also i am getting same error :D

[size="4"][font="Arial Narrow"][font="Garamond"]Attitude is a little thing that makes a big difference[/font][/font][/size][indent][/indent]

Share this post


Link to post
Share on other sites
Juvigy

Specify the full path to the excel file and try again.

Also check with IsObj($oExcel) if the open function has succeeded.

Share this post


Link to post
Share on other sites
Mecrazycoder

Specify the full path to the excel file and try again.

Also check with IsObj($oExcel) if the open function has succeeded.

After giving full path it seems to be working.But i am not sure,why that error occurred before, though the file is in script directory.Anyway its working now.Tanx dude

[size="4"][font="Arial Narrow"][font="Garamond"]Attitude is a little thing that makes a big difference[/font][/font][/size][indent][/indent]

Share this post


Link to post
Share on other sites
Juvigy

The function need full path name:

#Include <Excel.au3>
$oExcel = _ExcelBookOpen($sFilePath[, $fVisible = 1[, $fReadOnly = False[, $sPassword = ""[, $sWritePassword = ""]]]])

Parameters

$sFilePath Path and filename of the file to be opened 
$fVisible Flag, whether to show or hide the workbook (0=not visible, 1=visible) (default=1) 
$fReadOnly Flag, whether to open the workbook as read-only (True or False) (default=False) 
$sPassword The password that was used to read-protect the workbook, if any (default is none) 
$sWritePassword The password that was used to write-protect the workbook, if any (default is none)

Share this post


Link to post
Share on other sites
Mecrazycoder

The function need full path name:

#Include <Excel.au3>
$oExcel = _ExcelBookOpen($sFilePath[, $fVisible = 1[, $fReadOnly = False[, $sPassword = ""[, $sWritePassword = ""]]]])

Parameters

$sFilePath Path and filename of the file to be opened 
$fVisible Flag, whether to show or hide the workbook (0=not visible, 1=visible) (default=1) 
$fReadOnly Flag, whether to open the workbook as read-only (True or False) (default=False) 
$sPassword The password that was used to read-protect the workbook, if any (default is none) 
$sWritePassword The password that was used to write-protect the workbook, if any (default is none)

Umm..that sounds gud Tanx dude :D

[size="4"][font="Arial Narrow"][font="Garamond"]Attitude is a little thing that makes a big difference[/font][/font][/size][indent][/indent]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.