0

I'm facing a problem while writing the vb script for opening a .xls file that is given below..

Dim XLAPP

Set XLAPP = createobject("excel.application")

XLAPP.Visible =true

XLAPP.Workbook.open"d:\book1.xls"

When I run this script the pop window display an error like this:

The test run cannot continue due to an unrecoverable error. 'd:\book1.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct. If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted. Line (1): "Dim XLAPP".

When I write the script XLAPP.Workbook.Add then it adds an excel file but the above given script is not opening the excel file.

Jeetu
  • 1
  • 1
  • 1
    Try this: **XLAPP.Workbooks.open "d:\book1.xls"** I believe you need workbooks rather than workbook for this call, although either may be ok, are you sure the path is valid? – Matt Donnan Nov 26 '12 at 11:29
  • Ya,m sure the path is valid..i also used "workbooks"...now i got the solution.., when i use .xlsx rather than .xls then it works. Thanx sir,,, – Jeetu Nov 28 '12 at 07:34
  • Ah simple as that, may be worth bearing in mind that versions of Excel from 2007 onwards will be .xlsx, and any 2003 or earlier will be .xls – Matt Donnan Nov 28 '12 at 08:48

1 Answers1

0

The .Open method is within the Workbooks object collection (plural), not the Workbook object (singular)¹.

XLAPP.Workbooks.open "d:\book1.xls"

fwiw, you may have used the Workbooks collection without thinking about it in XLAPP.Workbooks.Add. The .Add method is not a member of the singular Workbook object and I could not get that to run; Run-time error 424: Object required.

¹ Kudos to Matt Donnan and his comment above for supplying the correct response.

Community
  • 1
  • 1