Finding which Workbook a Range belongs to

  • Thread starter Thread starter Aaron Queenan
  • Start date Start date
A

Aaron Queenan

Is there any way, using the Excel Object Model, to find out which Workbook a
Range belongs to?

Thanks,
Aaron Queenan.
 
Use range.workbook, e.g.

Dim c as range
Set c = activecell
msgbox c.workbook.name

Kevin Beckham
 
Alas, I'm using Excel 2002 (aka XP), and its Range object doesn't have a
Workbook property - only a Worksheet property. Also the Worksheet doesn't
to have a Workbook property.

Any other ideas?

Thanks,
Aaron.
 
It would appear that the Parent property of the Worksheet object returns the
Workbook.

Thanks,
Aaron.
 
Aaron,

Use the Parent property twice. The Parent of a Range is a
Worksheet, and the Parent of a Worksheet is the Workbook. For
example,


Dim Rng As Range
Dim WB As Workbook
Set Rng = Range("A1")
Set WB = Rng.Parent.Parent
Debug.Print WB.Name


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Back
Top