Excelmacros – VBA:select或范围不被接受为另一个函数的传递参数。 遇到运行时错误424

我有一个简单的Sub()来传递当前选定的单元格作为范围到另一个function,但我得到一个错误424:当我运行sub需要的对象。

我已经检查过,看到其他错误424职位,但都是不同于我的情况。

码:

 Public Sub ShowRemoveLicTypModal() Dim MsgBoxInput As Integer 'Show confirmation for removing license types MsgBoxInput = MsgBox("Would you like to remove the selected license types?", _ vbYesNo) Select Case MsgBoxInput Case vbYes RemoveLicenseTypeFromList (Selection) '==Error 424 encountered on this line ThisWorkbook.Save Case vbNo End Select End Sub 

行的RemoveLicenseTypeFromList (Selection)我得到错误。 它调用下面的函数。 我已经删除了这个函数的所有代码进行debugging,但我仍然得到错误。

 Private Function RemoveLicenseTypeFromList(InputRange As Range) 'Nothing here End Function 

我已经尝试了以下内容:

  • 将select分配给Rangevariables
  •  Public Sub ShowRemoveLicTypModal() Dim MsgBoxInput As Integer Dim Temp As Range Set Temp = Selection 'Show confirmation for removing license types MsgBoxInput = MsgBox("Would you like to remove the selected license types?", _ vbYesNo) Select Case MsgBoxInput Case vbYes RemoveLicenseTypeFromList (Temp) ThisWorkbook.Save Case vbNo End Select End Sub 
  • 观察Selection / Range被传递给RemoveLicenseTypeFromList ,我可以看到types是Object/Range OR( Range/Range )的Temp所以types应该匹配。
  • 在这里输入图像说明

    问题:
    什么可能导致这个错误,我该如何解决?

    我的select:
    单元格A13显示在图像上突出显示。 我也尝试改变select所有类似的结果。
    在这里输入图像说明

    删除括号!

     RemoveLicenseTypeFromList (Selection) 

    应该

     RemoveLicenseTypeFromList Selection 

    因为您没有将RemoveLicenseTypeFromList的返回值分配给一个variables。


    有一个不返回值的Function是没有意义的。 (它默认返回一个Variant/Empty ,但是总是返回一个Variant/Empty是没有意义的)如果Function不返回任何东西,你的Function应该是一个Sub

    函数应该返回一个值,vbe期待一个variables来接收函数RemoveLicenseFromList将返回。

    您可以在这里删除大括号RemoveLicenseTypeFromList (Temp)使其像RemoveLicenseTypeFromList Temp或调用您的函数Call RemoveLicenseTypeFromList (Temp)

    这也适用于Sub