I have two workbooks. A sheet “A” create a new instance of Excel.Application, then it asks its workbook “A” to open a workbook “B” and get the result from a function in workbook “B”.
I can manage to call workbook “B”‘s function from sheet “A”, but each time I call them from workbook “A” I have an error: Object doesn’t support this property or method (Error 438)
Code that reproduce the error:
Workbook “A”
ThisWorkbook
Sub call_fun(ByRef wb As Workbook)
MsgBox (wb.fun()) ' How to get the result?
End Sub
Sheet “A”
Sub sheet_main()
Dim app As Excel.Application
Set app = New Excel.Application
' Open the workbook B
app.Workbooks.Open ("pathtofilefile workbook A.xlsm")
' Call the workbook's a function
ThisWorkbook.call_fun (app.ActiveWorbook)
app.ActiveWorkbook.Close
app.Quit
Set app = Nothing
End Sub
Workbook B
ThisWorkbook
Function fun() As String
fun = "Function from workbook B"
End Function