当本地的Excel自定义函数突然停止工作时,以下是一些可能的解决方法和代码示例:
检查宏安全设置:确保Excel的宏安全设置允许执行自定义函数。在Excel中,依次点击“文件”>“选项”>“信任中心”>“信任中心设置”>“宏设置”,确保“启用所有宏”或“启用所有宏(不安全)”选项被选中。
检查函数代码:检查自定义函数的代码是否存在错误或逻辑问题。确保函数的语法正确,并且函数输入和输出的变量和范围正确。
示例代码:
Function MyCustomFunction(input1 As Integer, input2 As Integer) As Integer
' 函数代码
MyCustomFunction = input1 + input2
End Function
示例代码:
Function MyCustomFunction(input1 As Integer, input2 As Integer) As Integer
' 引用其他对象或函数
Dim rng As Range
Set rng = Worksheets("Sheet1").Range("A1:B10")
MyCustomFunction = rng.Cells(input1, input2)
End Function
示例代码:
在单元格中调用函数:=MyCustomFunction(A1, A2)
示例代码: 重新加载函数:
Sub ReloadCustomFunctions()
Application.Volatile False
Application.Run "ThisWorkbook.MyCustomFunction"
End Sub
以上是一些常见的解决方法和代码示例,希望能帮助你解决本地Excel自定义函数突然停止工作的问题。如果问题仍然存在,请尝试重新安装Excel或与Microsoft支持团队联系以获取进一步的帮助。