How to I bind EXCEL range in VBA macro from a C# Library that returns object[,] -


i have c# library has 2 methods. 1 returns integer , returns object[,]

public int returnint() {     //something return int } public object[,] return2darray() {     //returns twodimensionalarrayresponse; } 

now new vba , due legacy reasons need write vba macro rather vsto excel addin call library.

getting result first meathod easy. made assembly com visible , registered com interop , added reference in vba project , called using code below

sub gxsdata()     dim interopclass new excelinteropwrapper     dim result integer     result = interopclass.returnint()     msgbox "rows returned =" & cstr(result) end sub 

so far , good. want call second method data , bind excel.

sounds simple --> type should use hold data. tried dynamic array , did not work --> how bind dynamic range. let's 2d array 100*10 want bind range range.value = array know how in excel addin application in c# vba giving me real problems

any on great

i have found way . not perfect approach works me now. due c# skills wrote function write in excel in c# , called in vba macro. sure there pure macro ways of doing , like. because writing api , macro clients calling api. have presentation layer in macro. anyway c# here in case useful c# method

public static void binddatatoexcel( excel.range range,  object[,] response)           {               int rows = response.getlength(0);               int cols = response.getlength(1);               int n = 0;               excel.range newrange = range.get_offset(n, 0).get_resize(rows - n, cols);               newrange.value = response;           } 

my macro

sub gxsdata()     dim interopclass new excelinteropwrapper      dim o object     set o = interopclass.binddatatoexcel(activecell) end sub 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -