如何检测何时未传递可选的ByRef参数

时间:2015-10-21 14:02:36

标签: excel vba excel-vba

我试图检测是否传递了一个选择参数,但由于某种原因,所有常用函数(IsMissing()/ IsEmpty()/ IsNull())总是返回false。

这就是我正在尝试的:

public final void writeValue(Object v) {

   ...

   else if (v instanceof IBinder) {       
      writeInt(VAL_IBINDER);
      writeStrongBinder((IBinder) v);
   }

我也尝试将ws设置为Nothing或Null,但结果是相同的:

Public Sub SetValue(Key As String, Optional ByRef ws As Worksheet)
    If IsMissing(ws) Or IsEmpty(ws) Or IsNull(ws) Then
        ws = ThisWorkbook.Sheets(SheetName)
    End If

知道为什么会这样吗?

2 个答案:

答案 0 :(得分:2)

尝试is nothing

Private Sub CommandButton1_Click()
    Dim ws As Excel.Worksheet
    Set ws = ActiveWorkbook.Sheets("sheet1")

    'Call the sub both ways.
    SetValue "a"
    SetValue "a", ws
End sub

Public Sub SetValue(Key As String, Optional ByRef ws As Worksheet)
    If ws Is Nothing Then
        'We got a sheet
        MsgBox "We got no sheet"
    End If

    If Not ws Is Nothing Then
        'We got a sheet
        MsgBox ws.name
        MsgBox "We got a sheet"
    End If
End sub

答案 1 :(得分:1)

施工是什么都行不通。我在所有参数中都使用它。

li1 = page.xpath("//div[@class='div_a']//li") 

希望这会有所帮助。 :)