如何检查特定对象是集合还是字符串?

时间:2014-03-10 05:48:25

标签: vba outlook-vba outlook-2010

具体来说,我在Outlook 2010的上下文中使用ItemProperties。我希望从MailItem的ItemProperties中存储的信息中获取某些信息。大概是这样的:

Dim folderItems As Object
Set folderItems = folder.Items
Set thisItem = folderItems(index).ItemProperties
For p = 1 To thisItem.Count
    Debug.Print thisItem.Item(p).Name & " = " & thisItem.Item(p).Value 
    '= stuff involving thisItem.Item(p) etc
Next

问题是只要值是一个简单的String就可以正常工作,但是当涉及到诸如“Actions”之类的东西时,它显然会出错,其中值是一个集合/数组本身(具有.Count属性) ),或者根本不是一个直线字符串值。我试图想办法捕捉那些价值,以便在代码中以不同的方式处理它们,但我找不到它。

任何帮助?

1 个答案:

答案 0 :(得分:0)

使用typeOf() - 方法

示例:

If typeOf(thisItem.Item(p)) Is String Then
    MsgBox "String"
End If

检查对象是否支持属性:

If IsError(thisItem.Item(p).Value Then
    MsgBox "Item doesn't support value property"
Else
    MsgBox "Item has value property"
End If
相关问题