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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable equal to cell in another excel,file

Status
Not open for further replies.

griffitd

Programmer
Aug 20, 2002
189
GB
Hi

I'm after a line of code to make a variable equal to a cell value in another excel file.
i.e. somrthing like the following:

sValue = excelfile.xls.cells(r1c1)

Hope you can help thanks


 
Hi,

Code:
sValue = Application.Worksbooks("YourWB.xls").Cells(1,1).Value

Cheers,

Roel
 
Thanks for the reply

when I run the code i get "subscript out of range error"

Dave
 
Dave,

Whatever you have in place of 'YourWB.xls' is not the name of an open workbook; i.e. does not match any open workbooks.

Also, when you get that corrected, there needs to be a worksheet reference between the Workbooks and Cells identifiers. Example
Code:
sValue = Application.Worksbooks("YourWB.xls").Worksheets("Sheet1").Cells(1,1).Value


Regards,
Mike
 
Mike

I don't reallly want to open the spreadsheet. Does it need to be open?

Dave
 
Mike/Rofeu

The following works if I have the excel file open:

svalue = Application.Workbooks(sFileName1).Worksheets("Portrait").Cells(1, 1).Value

Can i get this to work without having it open.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top