![]() |
Using Variables in Two Workbooks
If I have two workbooks open, and Workbook A has a couple of arrays with
information I want to use in Workbook B, how do I go about getting the information into Workbook B? I thought using a Public declare would work, but it doesn't seem to. -- Bill @ UAMS |
Using Variables in Two Workbooks
You need to set a reference from Workbook A to Workbook B. In VBA with
Workbook B active and open, go to the Tools menu, choose VBA Project Properties and change the name to something unique like projBookB. Then, open Workbook A in VBA, go to the Tools menu, choose References, and put a check next to projBookB. Then, back in Workbook A, you can reference anything in WorkbookB by prefixing "projBookB." to the variable name. E.g,. X = projBookB.MyVariable If "MyVariable" occurs ONLY in workbook B, not in A, you can omit the "projBookB." prefix, but I think this is bad form. You should always use the prefix to indicate that you're linking to another library. Cordially, Chip Pearson Microsoft Most Valuable Professional, Excel, 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com On Mon, 15 Mar 2010 14:34:01 -0700, BillCPA <Bill @ UAMS wrote: If I have two workbooks open, and Workbook A has a couple of arrays with information I want to use in Workbook B, how do I go about getting the information into Workbook B? I thought using a Public declare would work, but it doesn't seem to. |
Using Variables in Two Workbooks
Thanks so much.
If you had a dollar for every time you have answered some of these questions, . . . . . -- Bill @ UAMS "Chip Pearson" wrote: You need to set a reference from Workbook A to Workbook B. In VBA with Workbook B active and open, go to the Tools menu, choose VBA Project Properties and change the name to something unique like projBookB. Then, open Workbook A in VBA, go to the Tools menu, choose References, and put a check next to projBookB. Then, back in Workbook A, you can reference anything in WorkbookB by prefixing "projBookB." to the variable name. E.g,. X = projBookB.MyVariable If "MyVariable" occurs ONLY in workbook B, not in A, you can omit the "projBookB." prefix, but I think this is bad form. You should always use the prefix to indicate that you're linking to another library. Cordially, Chip Pearson Microsoft Most Valuable Professional, Excel, 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com On Mon, 15 Mar 2010 14:34:01 -0700, BillCPA <Bill @ UAMS wrote: If I have two workbooks open, and Workbook A has a couple of arrays with information I want to use in Workbook B, how do I go about getting the information into Workbook B? I thought using a Public declare would work, but it doesn't seem to. . |
All times are GMT +1. The time now is 04:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com