HWL
Active Member
- Joined
- Dec 1, 2009
- Messages
- 462
This should work...
Dim tempfile1 As Workbook
Dim wsSheet As Worksheet
Set tempfile1 = Workbooks.Open(Range("D2"), ReadOnly, notify = False)
Set wsSheet = tempfile1.Worksheets(range("n2"))
MsgBox tempfile1.Worksheets(wsSheet).Cells(14, 1)
If fails on Set wsSheet = tempfile1.Worksheets(range("n2"))
I can use Set wsSheet = templfile1.Worksheets(1) and it will work fine, but I'm not certain the sheet will always be indexed as 1, thus the reason I want the user to supply the sheet name in cell N2.
What am I doing wrong here?
Dim tempfile1 As Workbook
Dim wsSheet As Worksheet
Set tempfile1 = Workbooks.Open(Range("D2"), ReadOnly, notify = False)
Set wsSheet = tempfile1.Worksheets(range("n2"))
MsgBox tempfile1.Worksheets(wsSheet).Cells(14, 1)
If fails on Set wsSheet = tempfile1.Worksheets(range("n2"))
I can use Set wsSheet = templfile1.Worksheets(1) and it will work fine, but I'm not certain the sheet will always be indexed as 1, thus the reason I want the user to supply the sheet name in cell N2.
What am I doing wrong here?