application.match

Oct 22, 2014 at 2:19 AM
Hi,
any ideas how I could convert this code in C# to be used in a dll with XL DNA?
res = Application.Match(ModelName, Range("models_names"), 0)
    If IsError(res) Then
        name = "N/A"
    Else
        ModelRow = CInt(res)
        name = ModelName
        VceonModelTTest = Range("models_Tjtest")(ModelRow, 1)
   ebd uf
Coordinator
Oct 22, 2014 at 8:56 AM
If you want to use the Excel COM object model in an Excel-DNA application, you can add a reference to the Excel interop assembly (Microsoft.Office.Interop.Excel). That makes the types available in your project.

Then you can get hold of the Application object with a call to ExcelDnaUtil.Application, (the result is of type Microsoft.Office.Interop.Excel.Application and you can access the Application members like Application.Match and Application.Range from there.

-Govert
Oct 22, 2014 at 4:13 PM
Thanks Govert,
so looking at Microsoft documentation I guess I should be using Application.Range and Application.WorksheetFunction.Match.

But looking at some examples on this site it looks like the suggestions is to use
dynamic xlApp = ExcelDnaUtil.Application;
but then there is no intellisense. Does I have to use the dynamic keyword? Is it possible to assign the type more specifically?

Thanks!
Oct 22, 2014 at 4:24 PM
I found this on a forum:
            // Get the correct application instance
            Excel.Application xlapp = (Excel.Application)ExcelDnaUtil.Application;
            // Get active workbook
            Excel.Workbook wbook = xlapp.ActiveWorkbook;
I'm getting Intellisense now...so we'll see how it goes!
Hopefully I'm on the right track!

Thanks again!
Oct 22, 2014 at 6:20 PM
H Govert,
so I was able to translate the syntax:
 Range("Parts[SKU]")
into
Excel.Application xlApp = (Excel.Application)ExcelDnaUtil.Application;
xlApp.Range["Parts[SKU]"]
however I'm not sure how to translate this structured reference range:
Range("Parts[SKU]")(newPartrw)
any ideas?

Thanks!
Coordinator
Oct 22, 2014 at 8:12 PM
Maybe you can try

xlApp.Range["Parts[SKU]"][newPartrw]

-Govert