ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Refer to Another Excel Workbook (https://www.excelbanter.com/excel-programming/403632-how-refer-another-excel-workbook.html)

hon123456

How to Refer to Another Excel Workbook
 
Dear All,
I have a Universal VBA in Personal.xls. Now If I open
book1.xls. Then the Personal.xls will
be opened too. However , If I want to refer to book2.xls, I need to
write the following hard code in Personal.xls.

test = [book1.xls]sheet1.range("a1")

What I want is that I do not want the book1.xls to be hard code. How
can I code it to let the filename be current workbook. If my workbook
is book2.xls or book3.xls . Then the VBA should
open book2 or book3. How can I write the variables for my current
workbook. Thanks.

Bob Phillips

How to Refer to Another Excel Workbook
 
test =Activeworkbook.Worksheets("Sheet1").Range("A1")


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"hon123456" wrote in message
...
Dear All,
I have a Universal VBA in Personal.xls. Now If I open
book1.xls. Then the Personal.xls will
be opened too. However , If I want to refer to book2.xls, I need to
write the following hard code in Personal.xls.

test = [book1.xls]sheet1.range("a1")

What I want is that I do not want the book1.xls to be hard code. How
can I code it to let the filename be current workbook. If my workbook
is book2.xls or book3.xls . Then the VBA should
open book2 or book3. How can I write the variables for my current
workbook. Thanks.





All times are GMT +1. The time now is 06:16 AM.

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