Search code examples
excelf#excel-dnavba

Importing User-Defined Functions Written in F# Using Excel DNA Into VBA Subroutines


I am currently using Excel DNA to write functions in F# and import them into Excel as formulas. Whenever selecting a cell, I am able to call any of the functions imported through Excel DNA. However, when attempting to create a new macro, I am only able to call the built-in formulas in my code, not the user defined ones. For example, If I write the following:

Sub a()
Range("A1").Value = ActiveWorkbook.Application.WorksheetFunction.Sum(2, 3)
End Sub

The macro is able to input "5" into cell A1. However, if I have a function written in F# that was imported through Excel DNA , the above logic does not apply since that function is not listed under ActiveWorkbook.Application.WorksheetFunction. Where would the user-defined functions/formulas be located?


Solution

  • Have a look at this tutorial. There are a few steps to go through. The tutorial uses C#, but it should work equally well for F#.