ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calling VBA Function from VSTO Code (https://www.excelbanter.com/excel-programming/431990-calling-vba-function-vsto-code.html)

Aritra Saha

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.


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com