Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 这些对话标题是什么类型的?_Vba_Email_Outlook - Fatal编程技术网

Vba 这些对话标题是什么类型的?

Vba 这些对话标题是什么类型的?,vba,email,outlook,Vba,Email,Outlook,我试图使用宏来归档电子邮件,但如果用户选择对话标题,我会遇到问题。这些标题的类型是什么 我试图在选择电子邮件时获取父文件夹,以确定是否应移动(或已移动)电子邮件。对于.MailItem我可以使用以下代码获取它: Set selection = ActiveExplorer.selection Set CurrentFolder = selection(1).Parent 但当仅选择对话头时,将返回错误“运行时错误‘440’:数组索引超出范围” 当尝试使用类似这样的if语句时: If Type

我试图使用宏来归档电子邮件,但如果用户选择对话标题,我会遇到问题。这些标题的
类型是什么

我试图在选择电子邮件时获取父文件夹,以确定是否应移动(或已移动)电子邮件。对于
.MailItem
我可以使用以下代码获取它:

Set selection = ActiveExplorer.selection
Set CurrentFolder = selection(1).Parent
但当仅选择对话头时,将返回错误“运行时错误‘440’:数组索引超出范围”

当尝试使用类似这样的if语句时:

If TypeOf selection Is Outlook.MailItem Then
    Set CurrentFolder = selection(1).Parent
ElseIf TypeOf selection Is Outlook.ConversationHeader Then
    'Set CurrentFolder
Else
    'Return error
End If
.ConversationHeader
不起作用,因为
ElseIf
语句返回
False

我应该使用什么
类型的
?然后,我应该使用什么代码来查找父文件夹?

选择属性返回对象,而不是单个项目。您需要循环选择项(对每个
使用“
”或对
使用“
”从1循环到
选择。使用
selection.Item(index)
)计数
)以获得所选项

您可以使用。

选择查看live Outlook对象及其属性、方法和事件。如果您的选择是提供的图像中指示的ConversationHeader,则项(索引)将引发异常

我无法找到该标题的实际对象类型,但有一些方法可以解决这个问题。一旦确定它不是邮件项,您可以检查
ActiveExplorer.Selection.GetSelection(Outlook.OlSelectionContents.olConversationHeaders)

最值得注意的是,它们表明

使用olConversationHeaders作为 参数返回具有Location属性的选择对象 等于OlSelectionLocation.olViewList

如果当前视图不是对话视图,或者 Selection.Location不等于OlSelectionLocation.olViewList, 使用olConversationHeaders作为参数调用GetSelection 返回具有Selection.Count等于0的Selection对象

正在对此进行快速测试

Dim oSelection = Selection
Set oSelection = ActiveExplorer.Selection.GetSelection(olConversationHeaders)
Print oSelect.Count 
--returns 1 when i have that odd header selected.  
--returns 0 when you have a mailItem within the header selected
此外,请看一看

我们可以很容易地根据以下几点来调整对某个问题的回答:

Set conversations = ActiveExplorer.Selection.GetSelection(Outlook.OlSelectionContents.olConversationHeaders)
Dim sItems As SimpleItems
    For Each Header In conversations
        Set Items = Header.GetItems()
        For i = 1 To Items.Count
            If TypeOf Items(i) Is Outlook.MailItem Then
            Debug.Print (Items(i).Parent)
            End If
        Next i
    Next Header
End Sub

值得注意的是,这只返回选定组中的电子邮件的标题,这些邮件位于进行选择的文件夹中。我相信您必须通过进入getConversations和Conversations对象向下/向上移动来进一步提高赌注。

我最终通过使用
ActiveExplorer.CurrentFolder
绕过了这个问题,但如果有人愿意,我仍然有兴趣找到我问题的答案。