【发布时间】:2019-06-29 21:59:30
【问题描述】:
我正在尝试列出特定文件夹中的所有电子邮件主题。只要项目不是邮寄项目,即约会等,我就会收到Run time Error 13。
后续问题:
1) 如何根据主题回复所有最新电子邮件,电子邮件可能在收件箱或已发送项目中。
2) 如何循环输入文件夹中的所有电子邮件,即单击“单击此处在 Microsoft Edge 上查看更多信息”可让您访问所有旧电子邮件。
Sub AccessInbox2()
'Early binding
Dim Olook As Outlook.Application ' to access all the libraries of outlook
Dim OmailItem As Outlook.MailItem ' To access emails in the inbox
Dim ONameSpace As Outlook.Namespace ' it is class which opens the gate for you to access all outlook folders. Unlike the Folder class, it exactly tells VBA which folder to use.
Dim Fol As Outlook.Folder ' Where we have emails with attachments stored
Dim Atmt As Outlook.Attachment ' a class which will help us in dealing wiht emails which as attachements
Dim TotalEmails As Long
Dim i As Integer
Set Olook = New Outlook.Application
Set OmailItem = Olook.CreateItem(olMailItem) 'to deal with emails
'messaging application protocal interface
i = 1
For Each OmailItem In Olook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Goldy").Items
'If TypeName(OmailItem) = "MailItem" Then
If OmailItem.Class = 43 Then
Sheet1.Cells(i, 7).Value = OmailItem.Subject
End If
i = i + 1
Next
End Sub
【问题讨论】:
-
outlook VBA script run-time error 13 randomly while iterating emails in a public folder 的可能重复项。查看接受的答案如何使用
Object变量,然后测试Class的变量。您在For Each循环中使用了MailItem变量。 -
非常感谢您的编辑。我也进行了该查询,因此包含 ('If TypeName(OmailItem) = "MailItem" ) 但它不起作用。此外,我请求帮助解决其他问题。我已经在这些问题上花了 10 个小时来找出解决方案,但还不够聪明,无法找到解决方案。
-
注意我的第二句话来解决你的主要问题。
-
该代码在遇到会议或约会时确实会处理少量电子邮件,我收到此错误。此外,我不知道代码如何开始其序列,即它将首先处理哪封电子邮件。我想知道是否有办法控制这种情况。抱歉,我两周前才学会了 VBA for Outlook。
-
我建议从链接的答案中更改一件事 - 我会使用
TypeOf ... Is而不是TypeName。