Finding which Workbook a Range belongs to

A

Aaron Queenan

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

Thanks,
Aaron Queenan.
 
K

Kevin Beckham

Use range.workbook, e.g.

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

Kevin Beckham
 
A

Aaron Queenan

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.
 
A

Aaron Queenan

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

Thanks,
Aaron.
 
C

Chip Pearson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top