sykes
Well-known Member
- Joined
- May 1, 2002
- Messages
- 1,885
- Office Version
- 365
- Platform
- Windows
Hi Folks
My public variables are only public at project level, and I don't understand. It almost seems as if I have to set Excel 2007 up differently?
As a simple test I've created 2 workbooks: "Book1" and "Book2".
I've inserted a new module in each book.
In the book1 module I've put:
In the book2 module I've put:
Next, I ran
Sub set_book1var()......
to assign a value to book1var
Then I ran
Sub get_vars() ....
from module 1.
the message box returned correctly with only a value for book1var, book2var was empty.
Then I ran Sub get_vars() from module 2, and both book1var and book2 vars were empty (i.e. module 1 in Book2 couldn't see book1var, and book2var wasn't assigned any value at that point.
Next, I ran
Sub set_book2var()......
to assign a value to book2var
Then I ran
Sub get_vars() ....
from module 2.
The message box only returned a value for book2var - book1var was empty.
Finally, I ran Sub get_vars() .... from module 1 again, and book1 var was still returned correctly, with book2var still empty.
Any suggestions please?
My public variables are only public at project level, and I don't understand. It almost seems as if I have to set Excel 2007 up differently?
As a simple test I've created 2 workbooks: "Book1" and "Book2".
I've inserted a new module in each book.
In the book1 module I've put:
Code:
Public book1var As String
Sub set_book1var()
book1var = "b1var"
End Sub
Sub get_vars()
MsgBox "Book1 variable = " & book1var & Chr(10) & "Book2 variable = " & book2var
End Sub
In the book2 module I've put:
Code:
Public book2var As String
Sub set_book2var()
book2var = "book2var"
End Sub
Sub get_vars()
MsgBox "Book1 variable = " & book1var & Chr(10) & "Book2 variable = " & book2var
End Sub
Next, I ran
Sub set_book1var()......
to assign a value to book1var
Then I ran
Sub get_vars() ....
from module 1.
the message box returned correctly with only a value for book1var, book2var was empty.
Then I ran Sub get_vars() from module 2, and both book1var and book2 vars were empty (i.e. module 1 in Book2 couldn't see book1var, and book2var wasn't assigned any value at that point.
Next, I ran
Sub set_book2var()......
to assign a value to book2var
Then I ran
Sub get_vars() ....
from module 2.
The message box only returned a value for book2var - book1var was empty.
Finally, I ran Sub get_vars() .... from module 1 again, and book1 var was still returned correctly, with book2var still empty.
Any suggestions please?