vba 用户定义的函数不会在 excel 上更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13961413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 18:54:28  来源:igfitidea点击:

User defined function does not update on excel

excelvbaexcel-vbauser-defined-functions

提问by Tono Nam

Possible Duplicate:
Refresh Excel VBA Function Results

可能重复:
刷新 Excel VBA 函数结果

I have simple function in excel:

我在excel中有简单的功能:

Function Test() As String

    Test = Now

End Function

and I am able to use it as:

我可以将它用作:

enter image description here

在此处输入图片说明

Now why is it that when I press the button:

现在为什么当我按下按钮时:

enter image description here

在此处输入图片说明

the value does not update !?

值不更新!?

For example if I have a cell with the formula =Rand()every time I click the calculate value I will get a different number. How can I make my custom function behave the same way ?

例如,如果=Rand()每次单击计算值时我都有一个带有公式的单元格,我将得到不同的数字。如何让我的自定义函数以相同的方式运行?

回答by chris neilsen

Add application.volatileto the job

添加application.volatile到作业

Btw, now()is available as an excel function

顺便说一句,now()可作为 excel 函数使用