One Variable Available In Three Workbooks

M

Minitman

Greetings,

I have 2 workbooks open and need to open a 3rd.

The 1st workbook needs to declare the names of all 3 workbooks as 3
variables (eg: wb1, wb2 and wb3) and do this before the last 2 are
opened.

Is this possible?

I looked at Public and Global declarations in MS help and came away
more confused then before.

JLGWhiz suggested I check out Chip Pearson's web site:
http://www.cpearson.com/excel/TrulyGlobalVariables.htm

to answer my question about global variables. That site has a lot of
very interesting things to say about global variables. However, I
noticed that the global variables, in the code they were talking
about, were limited to long numbers. To quote from the article -
"Note that these variables may contain only Long type numeric data."
This raised the question, don't my 3 variables have to be declared as
workbooks and not long numbers?

Can anyone clarify this question and maybe give some examples as to
how this can be accomplished?

Any help will be appreciated.

-Minitman
 
G

Gary Keramidas

maybe something like this, just change the names as necessary:

Dim file2 As String
Dim fpath As String
Dim wb2 As Workbook

file2 = "book1.xls"
fpath = ThisWorkbook.Path & "\"
Set wb2 = Workbooks.Open(fpath & file2, ReadOnly:=True)
 
M

Minitman

Hey Gary,

Thanks for the reply.

I'm afraid I may not have made the situation clear,

I need to declare the workbook names as variables when the first
workbook is opened and have these variables available in the other two
workbooks without redeclaring them. I know I can declare them as
Global but they are global only in the workbook that they are declared
in and not in the other two workbooks regardless of the order the
workbooks are opened in. I need these variables available in the
worksheet code section, the workbook open event and in the UserForm
code section.

Unfortunately, this code cannot do that.

Does anyone know of a way to make a truly global variable for workbook
names?

Any help would be appreciated.

-Minitman
 

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