Am 13.01.2011 18:54, schrieb Otto Moehrbach:
I have 2 files open. One file has the code. The other file's name is in the variable OrigWB. That file has only one sheet. I don't know the name of that sheet. How can I reference that sheet so that I can work with it? Specifically, I want to use the
statement With Workbooks(OrigWB).xxxxxxxx where the x's refer to that sheet. Alternatively, is there a way to find the name of that sheet? Thanks for your time. Otto
Every collection in the application accepts numbers and strings as parameters, i.E.
WorksBooks(1) is always the first workbook
WorksBooks("MyFile.xls") is a specific workbook
Sheets(1) is always the first sheet
Sheets("MySheet") is a specific sheet
Cells(1,1) or Range("A1") is always the first cell
Range("MyNamedRange") is a specific range
OrigWB.Sheets(1).Range("A1") is the first cell in that book.
On the other hand you can determine the sheet from a range with the Parent property
Range("A1").Parent.Name is the name of the sheet
Range("A1").Parent.Parent.Name is the name of the workbook
Range("A1").Parent.Parent.Parent.Name is the name of the application
or get the names from the objects
Sheets(1).Name is the name of the sheet
WorkBooks(1).Name is the name of the workbook
Application.name is the name of the application
Andreas.