ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Workbook Property or Method (https://www.excelbanter.com/excel-programming/353611-workbook-property-method.html)

Gary''s Student

Workbook Property or Method
 
How do I get the Workbook name associated with a range?

Function whereisit(r As Range) As String
MsgBox (r.Address)
MsgBox (r.Worksheet.Name)
whereisit = r.Address & r.Worksheet.Name
End Function

I need the workbook name as well as the Address and worksheet name.

Thanks in advance
--
Gary''s Student

Andy Pope

Workbook Property or Method
 
Hi,

You can make use of the Parent property. The example show it's use on
both the .Worksheet and Range object.

Function whereisit(r As Range) As String
MsgBox (r.Address)
MsgBox (r.Worksheet.Name)
MsgBox (r.Worksheet.Parent.Name)
whereisit = r.Address & r.Worksheet.Name & r.Parent.Parent.Name
End Function

Cheers
Andy

Gary''s Student wrote:
How do I get the Workbook name associated with a range?

Function whereisit(r As Range) As String
MsgBox (r.Address)
MsgBox (r.Worksheet.Name)
whereisit = r.Address & r.Worksheet.Name
End Function

I need the workbook name as well as the Address and worksheet name.

Thanks in advance


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Norman Jones

Workbook Property or Method
 
Hi Gary,

Try r.Parent.Parent.Name


---
Regards,
Norman



"Gary''s Student" wrote in message
...
How do I get the Workbook name associated with a range?

Function whereisit(r As Range) As String
MsgBox (r.Address)
MsgBox (r.Worksheet.Name)
whereisit = r.Address & r.Worksheet.Name
End Function

I need the workbook name as well as the Address and worksheet name.

Thanks in advance
--
Gary''s Student




Gary''s Student

Workbook Property or Method
 
Thank you both very much.
--
Gary''s Student


"Norman Jones" wrote:

Hi Gary,

Try r.Parent.Parent.Name


---
Regards,
Norman



"Gary''s Student" wrote in message
...
How do I get the Workbook name associated with a range?

Function whereisit(r As Range) As String
MsgBox (r.Address)
MsgBox (r.Worksheet.Name)
whereisit = r.Address & r.Worksheet.Name
End Function

I need the workbook name as well as the Address and worksheet name.

Thanks in advance
--
Gary''s Student






All times are GMT +1. The time now is 12:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com