open Excel spreadsheet

  • Thread starter Thread starter AlexD
  • Start date Start date
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
 
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
 
Thanks a lot, Doug.
But, the workbook has several spreadsheets. I need to open
it by name and to be able to see it.
 
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")
 
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)





.
 
Back
Top