在 VBA 中设置 UDF 描述时出错

Error while setting UDF description in VBA

我正在尝试为我的用户定义函数做一个描述。我使用这段代码没有问题:

Sub RegisterUDF23()
Dim FD As String


    FD = "Find the CN value based on landuse and soil type" & vbLf _
    & "CNLookup(Landuse As Integer, SoilType As String) As Integer"
          
Application.MacroOptions macro:="CNLookup", Description:=FD, Category:=14 _
, ArgumentDescriptions:=Array( _
        "Integer: (1 to 7)", "String: ""A"", ""B"", ""C"", ""D"" ")
End Sub

但是当我移动到第 24 个函数并想为它做同样的事情时,我在最后一行收到以下错误:

Run-time error '1004':

Method 'MacroOptions' of object '_Application' failed

这是第 24 个“RegisterUDF”的代码:

Sub RegisterUDF24()
Dim FD As String

    FD = "friction head loss in feet of water per 100 feet of pipe (ft H20 per 100 ft pipe)" & vbLf _
    & "HWfriction(roughness As Double, flow As Double, hyd_diameter As Double) As Double" & vbLf _
    & "HWfriction = Power(100 / roughness, 1.852) * Power(flow, 1.852) / Power(hyd_diameter, 4.8655) * 0.2083"
    
          
Application.MacroOptions macro:="HWfriction", Description:=FD, Category:=14

End Sub

Description 似乎限制为 255 个字符。将您的描述缩短 11 个字符以修复它。