How to determine which version of excel?

210 views
Skip to first unread message

zhenyu Chen

unread,
Feb 13, 2017, 4:56:58 PM2/13/17
to Excel-DNA
Is there any ways to determine excel version when user open excel?

Govert van Drimmelen

unread,
Feb 14, 2017, 4:44:33 AM2/14/17
to exce...@googlegroups.com

You can check ExcelDnaUtil.ExcelVersion.

 

-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 post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

zhenyu Chen

unread,
Feb 14, 2017, 10:35:00 AM2/14/17
to Excel-DNA
It works! Thank you !

Alberto Cherubini

unread,
Jan 20, 2020, 12:44:01 PM1/20/20
to Excel-DNA
Hi Govert,
I am currently running Excel365 locally on my machine (which updated recently, on the monthly channel).
If in excel I look at what version it is (i.e. in file/account) it tells me it is 1902,
excelDnaUtil.ExcelVersion returns 16.

Do you know what is the relationship between those two numbers?

The aim here is to find out whether an excel users (running our dll with UDF written using excelDna) has been upgraded to "dynamic array Excel" or not.

(this is because despite Microsoft attempts at making that upgrade backward compatible, they failed when UDF are involved, e.g. we had written our own auto-resizing functionality, which is now broken - so ideally we'd like to leave it working for users that have not been upgraded, and disable it automatically if they have).


On Tuesday, 14 February 2017 15:35:00 UTC, zhenyu Chen wrote:
It works! Thank you !

Alberto Cherubini

unread,
Jan 20, 2020, 3:00:37 PM1/20/20
to Excel-DNA
looking into microsoft docs/support pages, it seems the 4-char "version" e.g. "1912" is not v useful, as the same 4-char string can refer to different builds with different features.

Below I typoed, my version is not "1902" but "1912", in fact that is not unique...  the latest seems to be 16.0.12325.20298 

Also note that the excel/info/ reports inconsistent builds when you press "about"... I see 12324.20298 in the front, and .20280 in the about pop-up

Alberto Cherubini

unread,
Jan 20, 2020, 3:56:27 PM1/20/20
to Excel-DNA

Govert van Drimmelen

unread,
Jan 21, 2020, 4:58:39 AM1/21/20
to exce...@googlegroups.com

Hi Alberto,

 

As far as I know, the dynamic arrays feature was turned gradually across a range of versions.

So even if you know the exact version details of Excel, you would not know whether dynamic arrays are enabled.

 

The right way to detect dynamic arrays is probably to check for one of the built-in functions that accompany the feature, like SORT or FILTER.

I think the C API code for the FILTER function is 614.

 

Maybe you can help to test something like this:

 

        static bool? _supportsDynamicArrays; 

        [ExcelFunction(IsHidden=true)]

        public static bool SupportsDynamicArrays()

        {

            if (!_supportsDynamicArrays.HasValue)

            {

                try

                {

                    var result = XlCall.Excel(614, new object[] { 1 }, new object[] { true });

                    _supportsDynamicArrays = true;

                }

                catch

                {

                    _supportsDynamicArrays = false;

                }

            }

            return _supportsDynamicArrays.Value;

        }

 

I have not tried in a version that does not support dynamic arrays, but AFAIK it should throw an exception (as opposed to return #VALUE from the XlCall.Excel).

 

Please let me know if you have a chance to try it.

 

-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.

Patrick O'Beirne

unread,
Jan 21, 2020, 5:52:55 AM1/21/20
to exce...@googlegroups.com
If the user can type =SORT( then they have the dynamic arrays.
So in VBA you could test typename(evaluate("SORT(A1:A4)")) - variant()
if supported, error if not.

Charles Williams offers a CheckDA addin:
https://fastexcel.wordpress.com/2019/05/20/compatibility-of-office-365-dynamic-array-formulas/

Alberto Cherubini

unread,
Jan 21, 2020, 8:14:43 AM1/21/20
to Excel-DNA
Thanks Govert -  we will test that in both versions of excel.

(in case it doesn't throw, there is a similar one which does throw, using reflection, I'll post it here if needed)

To unsubscribe from this group and stop receiving emails from it, send an email to exce...@googlegroups.com.

Alberto Cherubini

unread,
Jan 21, 2020, 10:26:44 AM1/21/20
to Excel-DNA
Hi Govert, 
tested, and that code is behaving as desired with both version of excel.

Do you think it might be worthwhile to make it a bool property available in ExcelDnaUtil?

Govert van Drimmelen

unread,
Jan 21, 2020, 10:28:32 AM1/21/20
to exce...@googlegroups.com

OK great!

Yes that’s a good idea – I’ll add it there for the next version.

To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/448fc50b-f5ef-46ce-9725-1d60bf153155%40googlegroups.com.

Alberto Cherubini

unread,
Jan 28, 2020, 9:24:12 AM1/28/20
to Excel-DNA
Hi Govert,
one more thought. 
Using a throw is not ideal especially when running the addin under debug, as it will stop there every time (if you have an old excel).
I have tried to use reflection on the excel application object to find out there the new function e.g. FILTER is there or not, but standard reflection on the object does not show anything, I guess because it's COM.
Any thoughts on how to do it without the throw + try-catch?
tx
A

Govert van Drimmelen

unread,
Jan 28, 2020, 9:29:40 AM1/28/20
to exce...@googlegroups.com

Hi Alberto,

 

You can avoid the exception with something like this:

var returnValue = XlCall.TryExcel(614, out object result, new object[] { 1 }, new object[] { true });

// Now examine returnValue, which should be of type XlReturn – it will presumably be XlReturn.XlReturnSuccess for Dynamic Array Excel, otherwise XlReturn.XlReturnFailed or similar for non-DA Excel.

To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/9e98c97c-c54d-4a5b-acef-45e31da1e8df%40googlegroups.com.

Alberto Cherubini

unread,
Jan 28, 2020, 10:00:57 AM1/28/20
to Excel-DNA
thanks Govert I'll try that and let you know

Alberto Cherubini

unread,
Jan 28, 2020, 10:29:36 AM1/28/20
to Excel-DNA
Checked both cases, it works thanks
A.
Reply all
Reply to author
Forward
0 new messages