Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Reading data from range in .NET function via VBA call

54 views
Skip to first unread message

Stu McKenzie

unread,
Nov 8, 2024, 7:24:10 AM11/8/24
to Excel-DNA
Hello,

I'm trying to pass a table of data to .NET from VBA via a macro...

From what I've read, it seems like I can't pass a named range from VBA to .NET - is that correct?

What's the alternative? Must I pass the sheetName, the starting row and col numbers, and the count of rows and columns, and then read the data that way?

Is it not possible to simply get the data in VBA and pass it as an object[,] or something?

Thanks in advance


Govert van Drimmelen

unread,
Nov 8, 2024, 7:43:48 AM11/8/24
to exce...@googlegroups.com

You can define this UDF in your Excel-DNA add-in

 

        public static object UseThisData(object data)

        {

            // Inspect the data type of data and proceed from there

            return data.GetType().Name;

        }

 

And run it with

 

Sub Test()

    Dim arr(1 To 3, 1 To 2) As Variant

   

    ' Example of assigning values

    arr(1, 1) = "Item 1,1"

    arr(1, 2) = "Item 1,2"

    arr(2, 1) = "Item 2,1"

    arr(2, 2) = "Item 2,2"

    arr(3, 1) = "Item 3,1"

    arr(3, 2) = "Item 3,2"

   

    Debug.Print Application.Run("UseThisData", arr)

End Sub

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/ba447943-6d5b-4aa9-9cbc-6b026c89926en%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages