User-defined functions are not automatically calculated using Excel-DNA.

309 views
Skip to first unread message

Henry Huang

unread,
Aug 3, 2018, 3:42:46 AM8/3/18
to Excel-DNA
I developed a user custom function with Excel-DNA。When I opened the Excel for the first time, it can automatically calculate the formula, but when I saved Excel and turned it off, it didn't automatically calculate if I opened Excel again. My computer is win7 and Excel 2010. Is there anyone who has been in this situation?

Govert van Drimmelen

unread,
Aug 3, 2018, 4:28:15 AM8/3/18
to exce...@googlegroups.com
Under normal circumstances, user-defined functions do not recalculate when you open a sheet.

Exceptions would be when the file is in an older format, then Excel will recalculate when opened every time until the file is saved under the current Excel version.
Async and other RTD functions have a more complicated story.

So basically your observation is correct, and that is the intended Excel behaviour.

-Govert


From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of Henry Huang [xingq...@gmail.com]
Sent: 03 August 2018 09:42 AM
To: Excel-DNA
Subject: [ExcelDna] User-defined functions are not automatically calculated using Excel-DNA.

I developed a user custom function with Excel-DNA。When I opened the Excel for the first time, it can automatically calculate the formula, but when I saved Excel and turned it off, it didn't automatically calculate if I opened Excel again. My computer is win7 and Excel 2010. Is there anyone who has been in this situation?

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

Henry Huang

unread,
Aug 5, 2018, 10:42:51 PM8/5/18
to Excel-DNA
Thank you. But how can automatically calculate the function when open the Excel? (I use the async in the function).
Thank you very much!


在 2018年8月3日星期五 UTC+8下午4:28:15,Govert van Drimmelen写道:
Under normal circumstances, user-defined functions do not recalculate when you open a sheet.

Exceptions would be when the file is in an older format, then Excel will recalculate when opened every time until the file is saved under the current Excel version.
Async and other RTD functions have a more complicated story.

So basically your observation is correct, and that is the intended Excel behaviour.

-Govert

From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of Henry Huang [xingq...@gmail.com]
Sent: 03 August 2018 09:42 AM
To: Excel-DNA
Subject: [ExcelDna] User-defined functions are not automatically calculated using Excel-DNA.

I developed a user custom function with Excel-DNA。When I opened the Excel for the first time, it can automatically calculate the formula, but when I saved Excel and turned it off, it didn't automatically calculate if I opened Excel again. My computer is win7 and Excel 2010. Is there anyone who has been in this situation?

--
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 exc...@googlegroups.com.

Govert van Drimmelen

unread,
Aug 6, 2018, 1:45:46 AM8/6/18
to exce...@googlegroups.com
Your add-in can subscribe to the Application.WorkbookOpen event, and perform a CalculateFull on the Workbook that is opened.

-Govert
To post to this group, send email to exce...@googlegroups.com.

Henry Huang

unread,
Aug 6, 2018, 6:08:08 AM8/6/18
to Excel-DNA

Thank you very much. I use the Application.CalculateFull() to calculate the udf when open the workbook, and the udf can automatically calculate.
But I have another question, when opening a workbook, other opened workbook will also be recalculated. Is there any function or attribute to let the newly opened workbook recalculate? I used Workbook.ForceFullCalculation=false,but it doesn't seem to be useful。


在 2018年8月6日星期一 UTC+8下午1:45:46,Govert van Drimmelen写道:

Govert van Drimmelen

unread,
Aug 6, 2018, 6:19:53 AM8/6/18
to exce...@googlegroups.com
I'm not sure. Maybe you can ask on Microsoft's "Excel for Developers" forum.

-Govert

Henry Huang

unread,
Aug 6, 2018, 10:13:53 PM8/6/18
to Excel-DNA
Thank you. I had been asked the question at the forum yesterday.
I used "object asyncResult = ExcelAsyncUtil.Run" in the function. I want to use more threads to caculate UDF. Can I set the number of asynchronous threads in Excel-DNA? Or can only be determined by Excel itself


在 2018年8月6日星期一 UTC+8下午6:19:53,Govert van Drimmelen写道:

Govert van Drimmelen

unread,
Aug 7, 2018, 4:38:27 AM8/7/18
to exce...@googlegroups.com

The default async implementation (which you get when you call ExcelAsyncUtil.Run) schedules your work on the .NET ThreadPool. So you have some control over the number of threads by settings the ThreadPool properties.

 

You can take complete control of the async implementation by using .NET Tasks explicitly, then you can control the TaskScheduler to restrict or control the number of threads yourself. See this example: https://github.com/Excel-DNA/Samples/tree/master/LimitedConcurrencyAsync and this related discussion https://groups.google.com/forum/#!msg/exceldna/tCbtb2zmQrs/IiBsc-5xeSgJ .

 

-Govert

Henry Huang

unread,
Aug 26, 2018, 10:07:18 PM8/26/18
to Excel-DNA
Dear Govert,
  I'm sorry to disturb you again. I have another question.I used Excel's function in UDF, such as Today (), UDF will continue to recalculate. Is there any way to make the function count only once?



在 2018年8月7日星期二 UTC+8下午4:38:27,Govert van Drimmelen写道:

Govert van Drimmelen

unread,
Aug 27, 2018, 1:54:21 AM8/27/18
to exce...@googlegroups.com
Async functions don't interact well with 'volatile' Excel functions like TODAY and RAND.
You might need to implement your own non-volatile version of these functions instead.

-Govert
Reply all
Reply to author
Forward
0 new messages