Bryan has attended:
Excel VBA Intro Intermediate course
Creating a Public variable Excel 2007
Good Afternoon,
I am picking up a variable from a user form text box.
I am able to keep the variable within the current workbook.
How do i go about moving the variable into another workbooks VBA code which is opened by the original VBA code?
I have tried to declare the variable as public.
Many thanks,
RE: Creating a Public variable Excel 2007
Hi Bryan,
Can you clarify the following for me
Do you wish to write the value of the variable into the second workbook, or do you first wish to process it in a module in the second workbook?
Thanks
Stephen
RE: Creating a Public variable Excel 2007
Hi,
what i am trying to do is take a value that is inputted trough a user form within the first workbook. the first workbook then opens a second workbook i then need to pass the variable that was inputted from the user form into the second workbooks module (it is a connection string to a SQL database).
many thanks
RE: Creating a Public variable Excel 2007
Hi Bryan
Thanks for the update
A public variable is visible to any module within that project (workbook), but cannot be passed to modules in other projects.
The simplest solution is to write code in the first workbook that places the variable in a cell in the second workbook. You can then use code in the second workbook to copy that cell's value to another variable and use it from there.
Regards
Stephen