I am running an Excel Macro from an Outlook Macro, and I need to get the Excel Macro's return.
My Outlook Macro's code looks like this:
Dim excelApp As Object
Set excelApp = CreateObject("Excel.Application")
excelApp.Workbooks.Open "C:\Users\meej\Documents\Book1.xlsm"
If excelApp.Run("ThisWorkbook.Foo", true) Then
Debug.Print "TRUE"
Else
Debug.Print "FALSE"
End If
excelApp.Quit
Set excelApp = Nothing
My Excel Macro looks like this:
Public Function Foo(ByVal result as Boolean) as Boolean
Foo = result
MsgBox Foo
End Function
My MsgBox pops up and shows true but in Outlook I always print "FALSE". Am I misusing Run?
resultnot being cast correctly.MsgBoxcorrectly?MsgBox VarType(result)inside your functionRunwas"Module1.Foo", False. My Immediate window printed properly.