Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading an Excel worksheet by variable

Status
Not open for further replies.

AOLBoy

IS-IT--Management
May 7, 2002
68
GB
I am accessing an MS Excel file and wish to position on a specific worksheet using a variable.

this is my code:
***********************************
Dim ExcelApp As Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet

Set ExcelApp = CreateObject("Excel.Application")
Set ExcelWorkbook = ExcelApp.Workbooks.Open(FN)
Set ExcelSheet = ExcelWorkbook.Worksheets(WS)
********************************

FN contains the pathname and filename of the excel file
WS contains the name of the worksheet

I can't seem to access the worksheet in this manner. I get a subscript out of range error.

Can anybody help me please?



 



Hi,

"I get a subscript out of range error."

On what statement? Please post.


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Where does your filename and sheetname come in?

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Sorry folks, this was a red herring. I have resolved my problem - the code above worked, the error I was getting referred to me trying to access a non-existent cell in the worksheet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top