Using Variables in Two Workbooks

B

BillCPA

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

Chip Pearson

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
 
B

BillCPA

Thanks so much.

If you had a dollar for every time you have answered some of these
questions, . . . . .
 

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