Jump to content
Sign in to follow this  
WayneCusack

Problem accessing an Excel file

Recommended Posts

WayneCusack

I am new to AutoIt and could dearly use a little assistance.

The ultimate goal is that I am trying to access an on-line database of lawyers and copy the contact information to an Excel spreadsheet. The short range goal is simply to make sure that I am accessing the Excel file without difficulty; however, I am getting an error message when I run my code. To do that, I open the Excel file and run the code below. It produces the following error message:

Line 1055 (File "C:\Program Files\AutoIt3\Include\Excel.au3");

Local $iTemp = $oExcel.ActiveWorkbook.Sheets.Count

Local $iTemp = $oExcel.ActiveWorkbook^ ERROR

Error: The requested action with this object has failed.

The sample code installed with AutoIt3 works properly to create a new workbook, but mine which accesses an existing workbook does not. The code I am using is as follows:

#include <Excel.au3>

#include <Array.au3>

WinActivate("Microsoft Excel - Toronto Lawyers new")

WinWaitActive("Microsoft Excel - Toronto Lawyers new")

$sFilePath = "C:\Wayne\Jobs\Emergency Law Services\Toronto Lawyers New.xls"

Local $oExcelDoc = ObjGet($sFilePath)

$aArray = _ExcelSheetList($oExcelDoc)

;_ArrayDisplay($aArray, "All The WorkSheets In this WorkBook")

To isolate the error I used ";" to neutralize lines - by this method I found the problem arises when the following line is run:

$aArray = _ExcelSheetList($oExcelDoc)

I can't figure out what I am doing wrong, and any help would be appreciated.

Wayne Cusack

Share this post


Link to post
Share on other sites
BugFix

If Excel is always open, you get an object reference with: $oExcel = ObjGet('', 'Excel.Application')

Now can use it like known.

Edited by BugFix

Best Regards BugFix  

Share this post


Link to post
Share on other sites
WayneCusack

If Excel is always open, you get an object reference with: $oExcel = ObjGet('', 'Excel.Application')

Now can use it like known.

Share this post


Link to post
Share on other sites
WayneCusack

Thanks - works beautifully now.

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  

×