ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing a variable between workbooks (https://www.excelbanter.com/excel-programming/298848-passing-variable-between-workbooks.html)

Rich Cooper

Passing a variable between workbooks
 
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.



Bernie Deitrick

Passing a variable between workbooks
 
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

"Rich Cooper" wrote in message
...
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.






All times are GMT +1. The time now is 09:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com