在VBA Excel中调用sub中的函数时"对象必需"

use*_*529 2 excel vba function object required

在我的VBA程序中为excel; 我有一个名为"ParamCheck"的函数,它获取四个"双"变量,检查它们并返回一条消息"string".

Function ParamCheck(airSpeed As Double, FCUvalue As Double, _
            altitude As Double, terrainElevation As Double) As String

            If airSpeed < MIN_CONTROL_SPEED Then                            
            'check if airspeed is less than 119 ft/min or not
                ParamCheck = "Airspeed is less than minimum control speed"

            ElseIf FCUvalue > FCU_VALUE_LIMIT Then                          
            'check if FCU value if greater than 10 or not
                ParamCheck = "FCU value is greater than limit"

            ElseIf FCUvalue < 0 Then                                        
            'check if FCU vlaue is negative or not
                ParamCheck = "FCU value is negative"

            ElseIf altitude <= terrainElevation Then                        
            'check if altitude is greater that terrain of elevation or not
                ParamCheck = "Altitude is less than terrain elevation"

            Else                                                            
            'if all the parameters are valid print a "Valid" message
                ParamCheck = PARAMS_OK
            End If
End Function
Run Code Online (Sandbox Code Playgroud)

现在我需要在我的子程序中调用此函数.这是代码

Dim checkParam As String    ' result of validity check of parameters
Set checkParam = ParamCheck(speedAir, valueFCU, aboveSea, elevationTerrain)
Run Code Online (Sandbox Code Playgroud)

运行时它给我这个错误"对象需要"并突出显示"checkParam"

Adr*_*oix 10

您不需要SetString类型的关键字,这就是原因.

与其他编程语言不同,VBA将String视为数据类型,而不是Object.

关键字Set用于指定对象的引用(Worksheet,Range等).

如果您尝试为数据类型分配引用,则会出现错误.