Passing a variable between workbooks

R

Rich Cooper

Is possible to pass a variable between workbooks? I can do it by stroing
the value of the variable to a cell or range then inside that workbook.
Then through the second workbook i go to that cell or range in the first
workbook and store it to a cell or range in the second workbook. Then i
create a variable in the second workbook which has a value of that cell or
range i just called over from the first workbook. Is there a simple way of
doing this with out storing to cells the calling it across workbooks and
storing to a cell then defining it to a variable in the second work book or
is that the only way? Any suggestion or answers would be great. Sorry if
it sounds confusing.
 
B

Bernie Deitrick

Rich,

You can have a procedure that accepts a variable that is passed to it.

In Book1.xls:

Sub PassVariableToBook2()
Dim MyStr As String
MyStr = "test"
Application.Run "'Book2.xls'!TryNow", MyStr
End Sub

In Book2.xls:

Sub TryNow(inVar As String)
MsgBox "I just received " & inVar
End Sub

HTH,
Bernie
MS Excel MVP
 
Top