jars121
jars121

Reputation: 1147

Assign result of external function to variable

I have a master workbook (wbMaster) and a slave workbook (wbSlave). The master workbook has a function which returns the result of user input into a form within the master workbook. The function works as required.

I would like to be able to assign the result of calling that function to a variable, from within the slave workbook.

Public Sub Workbook_Open()

    'The following line (in the wbSlave workbook) runs the function
    'in the master workbook as required, however I don't know how to
    'assign the result of the function to a local variable within the
    'slave workbook.

    Application.Run "wbMaster.xlsm!FormResult.Result"

    'This is what I'm trying to achieve:
    LocalResult = Application.Run "wbMaster.xlsm!FormatResult.Result"

    'but this throws a Compile Error (Expected: end of statement).

End Sub

Is there a simpler approach to this that I'm missing?

Normally, I'd simply pass the function result as an argument when calling the slave workbook, but doing so seems to cause security issues when passing arguments to the Workbook_Open function.

Upvotes: 0

Views: 134

Answers (1)

Tim Williams
Tim Williams

Reputation: 166126

LocalResult = Application.Run("wbMaster.xlsm!FormatResult.Result")

You need the parentheses if you're returning a value.

Upvotes: 1

Related Questions