Jeetu
Jeetu

Reputation: 1

Error in vb script for .xls location finding

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.

Upvotes: 0

Views: 646

Answers (1)

user4039065
user4039065

Reputation:

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.

Upvotes: 0

Related Questions