excel worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I go to a specific worksheet in an excel workbook.
I have the following code but, it takes me to a random
spreadheet...

With oApp.Application
.Visible = True
'Open the Workbook
.Workbooks.Open "c:\graphs.xls"
End With

Thanks
 
-----Original Message-----
How do I go to a specific worksheet in an excel workbook.
I have the following code but, it takes me to a random
spreadheet...

With oApp.Application
.Visible = True
'Open the Workbook
.Workbooks.Open "c:\graphs.xls"
End With

Thanks
.
Hi, try

dim objXlBook as object
dim objXlSheet as object

With oApp.Application
.Visible = True
'Open the Workbook
set objXlBook = .Workbooks.Open("c:\graphs.xls")
End With

set objXlSheet = objXlBook.Worksheets("name of sheet")

ps I recommend posting excel questions to the excel
usergroup

Luck
Jonathan
 
Does not work...tells me subscript out of range. The
reason I posted this question here is because I am using
this code in an Access form.
 
I believe objBook is actually going to be a collection (even if there's only
one workbook open).

Try

set objXlSheet = objXlBook.ActiveWorkBook.Worksheets("name of sheet")

Even if you're running from Access, the Excel-related VBA is going to be the
same. The only difference will be that if you're using late binding (in
other words, if you don't have a reference set to Excel, but are using
CreateObject or GetObject to instantiate oApp), you won't be able to use
intrinsic constants, which the Excel gurus will probably include in their
sample code.
 
Back
Top