View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Aritra Saha Aritra Saha is offline
external usenet poster
 
Posts: 1
Default Calling VBA Function from VSTO Code

Hi,

I need to call a VBA Function (accepting parameters and returning values)
from a VSTO Add In Code base. The macro code base in the .xlsm file is as
follows :-

Sub SayHelloVBA()
MsgBox "Hello from VBA."
Dim k As Integer
k = tesFn(10, 5)
MsgBox k
End Sub

Public Function tesFn(ByVal i As Integer, ByVal j As Integer) As Integer
tesFn = i + j
End Function

I am able to call the Subroutine SayHelloVBA succesfully from VSTO Using the
following code :-
Globals.ThisWorkbook.Application.Run("Sheet1.SayHe lloVBA")

However, I am not able to call any of the Functions (since, I need return
values from VBA, for which I need functions !)

I have tried the following syntax :-
Dim answer As Integer
answer = Globals.ThisWorkbook.Application.Run("Sheet1.tesFn ", 10, 5)
MsgBox(answer)

However, this is returning zero in the answer variable. Please advice.