creating public variable excel

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Creating a Public variable Excel 2007

Creating a Public variable Excel 2007

resolvedResolved · Low Priority · Version 2007

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

RE: Creating a Public variable Excel 2007

Thank you very much for your help Stephen.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Trace Dependents / Precedents without the blue arrows

Rather than using the toolbar you can press CTRL+] which is the equivelent of trace dependants and CTRL+[ for precendants. Both of these ways though will not show the blue arrows but jump to the cell containing the formula.

View all Excel hints and tips


Server loaded in 0.09 secs.