open Excel spreadsheet

A

AlexD

I'm trying to open and see Excel spreadsheet (by name)
from Access by using the following:

Dim xlApp As Excel.Application

Dim xlBook As Excel.Workbook

Set xlApp = CreateObject("Excel.Application")

Set xlBook = xlApp.Workbooks.Open("Book1")
ActiveWorkbook.Worksheets("WorksheetName")

But, I'm getting the error message that it's out of range.

Thanks
 
D

Douglas J. Steele

The line

ActiveWorkbook.Worksheets("WorksheetName")

is incorrect: you need to continue using the objects you've created.

Try adding

Dim xlSheet As Excel.Worksheet

then

Set xlSheet = xlBook.ActiveWorksheet
 
A

AlexD

Thanks a lot, Doug.
But, the workbook has several spreadsheets. I need to open
it by name and to be able to see it.
 
D

Douglas J. Steele

Sorry: I was copying from an example I had kicking around and forgot to
change it to be consistent with what you had!

Set xlSheet = xlBook.Worksheets("WorksheetName")
 
A

AlexD

Thank you very much, Doug.
-----Original Message-----
Sorry: I was copying from an example I had kicking around and forgot to
change it to be consistent with what you had!

Set xlSheet = xlBook.Worksheets("WorksheetName")


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)





.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top