Fairly new to VBscript and VBA... hoping for some help and that it's an easy answer...
I'm calling a Macro / Function in Excel VBA from VBscript. The call to the Function should return a number. Using VBA debug in Excel, the function appears to work properly (in this example, it displays a value of 1), but when I call the Macro / Function and attempt to echo the value in VBscript it shows as "Empty".
How can I get the value from VBA back to VBscript?
Thanks for your help
Example of VBscript code:
Set excelOBJ = CreateObject("Excel.Application")
Set workbookOBJ = excelOBJ.Workbooks.Open("C:\variable.xlsm")
excelOBJ.Application.Visible = True
excelOBJ.DisplayAlerts = False
REM mostly for testing purposes
Dim returnValue
returnValue = 10
Wscript.Echo "'returnValue' value before call to macro function = " & returnValue
Wscript.Echo "'returnValue' TypeName before call to macro function = " & TypeName(returnValue)
returnValue = excelOBJ.Run("ThisWorkbook.getNum")
Wscript.Echo "'returnValue' value after call to macro function = " & returnValue
Wscript.Echo "'returnValue' TypeName after call to macro function = " & TypeName(returnValue)
excelOBJ.quit
Example of VBA in Excel:
Public Function getNum()
getNum = 1
Debug.Print "getNum value = " & getNum
End Function
Output:
'returnValue' value before call to macro function = 10
'returnValue' TypeName before call to macro function = Integer
REM Inside Excel VBA editor
getNum value = 1
'returnValue' value after call to macro function =
'returnValue' TypeName after call to macro function = Empty
returnValue = excelOBJ.Run("'Variable.xlsm'!.getNum")