Check for array formula within a macro-style Excel UDF - excel

I'm using Excel-DNA to create UDFs within Excel and NetOffice for version-independent automation calls. Within a macro-type function, I'm able to use the following to get the formula from a cell:
ExcelReference cellRef; // of course in reality this is assigned
var formula = (string)this.excelCall(XlCall.xlfGetFormula, cellRef);
Additionally though, I'd like to know whether this is part of an array formula, and if so what its extent is. Using Excel automation, I can use something like:
Range("A1").HasArray
Range("A1").CurrentArray.Address
However, Microsoft discourage the use of automation within UDF calls: https://support.microsoft.com/en-us/kb/301443
So, is there a way to get the the HasArray and CurrentArray properties via the C API, or does anyone know if it's okay (in the context of a UDF declared as macro-type) to use automation?

The GET.CELL information function, with information type_num 49 will return whether the cell is part of an array. From your Excel-DNA (macro-type) function:
bool isArray = (bool)XlCall.Excel(XlCall.xlfGetCell, 49, cellRef);

Related

Calling a webservice URI from excel sheet cell

I need to call a webservice URI from an Excel cell. I know this can be done using the in-built WEBSERVICE function. However, passing the parameters on the fly to the URI can be a bit tedious.
For.eg. my webservice URI is :
http://localhost/getEmployeeSalary?emloyeeName=MisterFoo&employeeId=101
The values MisterFoo and 101 are pulled from other cells in the sheet.
So what I am looking for is to call the service like an Excel function (SUM, AVG, etc.), which would look like
=getEmployeeSalary(A2,B4)
where A2 cell contains MisterFoo and B4 cell contains 101.
For now, I have tried looking for a solution but the only thing that comes up is using ribbons (Excel Add-in project in Visual Studio) that take parameters and store the value in a pre-defined cell. This is not what I am looking for though.
Any help or suggestion would be appreciated. Thanks in advance!
you could potentially use a user defined function?
https://support.office.com/en-sg/article/Create-Custom-Functions-in-Excel-2007-2f06c10b-3622-40d6-a1b2-b6748ae8231f
You need to develop an add-in where you can run secondary threads calling web services because such operations can take a lot of time get results. See Walkthrough: Creating Your First Application-Level Add-in for Excel for more information.
I do this all the time using the Excel Concatenate function.
=WEBSERVICE(CONCATENATE("http://localhost/getEmployeeSalary?emloyeeName=",A2,"MisterFoo&employeeId=",B4))
You can use the Evaluate Formula option from the Formulas menu item to step through the function.
Hey guys I really appreciate your help. This is what I was looking for: http://blogs.msdn.com/b/eric_carter/archive/2004/12/01/writing-user-defined-functions-for-excel-in-net.aspx

Excel wouldn't import Access query that contains VBA calls

Access and Excel 2013
Trying to use an Access base as a data source in Excel, it seems like if a query calls a VBA function, Excel doesn't see it.
This query shows up in Excel:
SELECT "StaticValue" AS static_value;
This one doesn't:
SELECT my_function() AS value_from_vba;
The code of the module containing my_function being:
Option Compare Database
Function my_function() As String
my_function = "ValueFromVBA"
End Function
How can I call a VBA function in an Access query and link this query to Excel ?
Hmm perhaps;
Make table and query the table (as stated in comments)
My preferred is just to export the data from access into a new worksheet that you need in excel, then you can do what you want with it if you are only getting values. Then you can go back in and update anything after (in your access tables) with VBA should you need it
I ended up creating a table (SELECT … INTO …) that I refresh on a regular basis. This table is linkable within Excel. It is probably a dirty trick, but it does the job.

Get a collection of functions in Excel

Is there a way to get a collection of all of the functions that are currently available to Excel, including user-defined functions?
I am trying to create an application add-in that uses function usage information, so I need to be able to parse out Excel function calls in formulas.
If you want to parse out function names from formulas see my blog post on how to do it:
http://fastexcel.wordpress.com/2013/10/27/parsing-functions-from-excel-formulas-using-vba-is-mid-or-a-byte-array-the-best-method/
If you want to find out information about built-in and XLL functions see this blog post
http://fastexcel.wordpress.com/2013/12/09/finding-out-if-a-function-is-volatile-or-multithreaded-using-vba-udfs-for-udfs/
If you want to find out all available VBA UDF functions you could parse them out from the VBA if your code is allowed access to the VBA.
I don't know how to find available automation UDFs, they are not registered

MD5 Hash function in excel without using VBA

I need a function that will take an entire cell value in Excel and convert the value into its MD5 hash equivalent in a new cell.
Is there a formula in excel that does that? I need a solution that doesn't use VBA. Is this possible?
Without VBA is possible to use webservice formula that invoke a webservice that return the md5sum.
Explanation
=WEBSERVICE(B4)
Result: 89374b6dda3bb0e16132b21fb9887f1d
=CONCAT("https://md5sum.herokuapp.com/?text=";ENCODEURL(B3))
Result: https://md5sum.herokuapp.com/?text=bruno%20tafarelo
B3 cells contains the text to be coded
Value: bruno tafarelo
This web service was developed by me as all the services on internet require a POST method and Excel is only able to perform GET request. It's hosted in a free service and I don't know for how long it will be available.
Web service source code: https://github.com/btafarelo/md5sum

Is it possible to create an efficient UDF alternative to Excel's CUBEVALUE function?

We'd like to create a simpler alternative to Excel's CUBEVALUE function for retrieving data from an OLAP server. The details aren't critical, but briefly, our function will "know" the source connection and accept a very simple ticker-like parameter and a date, in place of CUBEVALUE's MDX-style parameters. This is for internal use within our firm, just FYI.
However, Excel has optimized CUBEVALUE so that calls to the OLAP server are batched.
Question: Is there a way to code the new function so that it can similarly batch calls rather than issue a separate query for each cell?
Looks like this will be possible starting in Excel 2010. According to http://blogs.msdn.com/excel/archive/2010/01/27/programmability-improvements-in-excel-2010.aspx Excel 2010 adds support for asynchronous UDF's. That's exactly what's needed to mimic the performance of CUBEVALUE.

Resources