Hi everyone!
I am trying to pass a variable from a procedure to a called procedure which resides in a different project. It seems that just by making the variable Public it doesn't get transferred to a out of project procedure.
I appreciate any help!
rgds, J
Try this:
Create two workbooks - I've left them with their default names of Book1 and Book2. In the VB Editor name the Project for Book1 as Phase1 (it's not really necessary to give the default "Project1" a new name but it helps to be able to identify Project1 in Book1.xls from the Project1 in Book2.xls). Insert a new module in Book1 - call it Globals. Enter the following code into the Globals module:
Public Test As String
Sub tester()
Test = "Hello"
End Sub
Save the workbook with it's default name (on the desktop for the purposes of this test) and leave it open.
In book2 insert a new module.
In that module insert the following code:
Sub tester2()
Dim teststring As String
teststring = test & " World!"
End Sub
In Book2, go to Tools|References.
You should see a Reference to the project you renamed as Phase1.
Check the box next to it and OK out.
You should now see a "References" entry in the Project Explorer pane.
Save the workbook and leave it open.
If you now run tester2 in book2 the message box will just say " World!"
That's because the Global variable in book1 has not been set because that subroutine has not been run yet. So back to book1. Run tester. You have now set the Public string variable Test to "Hello". Now when you run tester2, Test is passed to the referenced workbook project (as "Hello") and the Message box should read "Hello World!".
Is that what you wanted?