2015-09-07 41 views
0

我有一個主工作簿(wbMaster)和一個從工作簿(wbSlave)。主工作簿具有將用戶輸入的結果返回到主工作簿內的表單的功能。該功能按需要工作。將外部函數的結果賦值給變量

我希望能夠將該函數的調用結果從slave工作簿中分配給一個變量。

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 

有沒有更簡單的方法來解決這個問題?

正常情況下,我只是在調用從屬工作簿時將函數結果作爲參數傳遞,但這樣做似乎在將參數傳遞給Workbook_Open函數時會導致安全問題。

回答

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

如果您要返回值,則需要括號。

+0

謝謝蒂姆!我不知道我錯過了那麼簡單的事情! – jars121