Vba 如何检查特定对象是集合还是字符串?
具体来说,我正在Outlook 2010的上下文中使用ItemProperties。我想从MailItem的ItemProperties中存储的信息中获取某些信息。大致如下:Vba 如何检查特定对象是集合还是字符串?,vba,outlook,outlook-2010,Vba,Outlook,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.Ite
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
问题是,只要值是一个简单的字符串,这种方法就可以正常工作,但当涉及到“操作”时,显然会出现错误,其中值本身就是一个集合/数组(具有.Count属性),或者根本不是一个简单的字符串值。我正试图想出一些方法来捕捉这些类型的值,以便在代码中以不同的方式处理它们,但我找不到一种方法
有什么帮助吗?使用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
TypeName()
例如?不,这个和TypeName()都不起作用。我需要处理项的值,在某些情况下,对象根本不支持value属性。这两种方法在这些情况下都被卡住了。哦,我不理解你的问题。我编辑了我的答案