如何显示下一个项目

时间:2016-02-14 11:56:19

标签: vba outlook-vba

如何通过宏打开每个邮件的Outlook收件箱,这真的很有帮助,但我想一次只打开一封邮件,当我关闭第一封邮件时,我想再次点击宏打开下一封邮件(1,2) ,3,4)?

请帮帮我

回答我所拥有的:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub LoopThruEmails()
    'open outlook inbox mail by vba
    Dim i As Long
    Dim InboxItems As Outlook.Items
    Dim thisEmail As Outlook.MailItem
    Set InboxItems = GetItems(GetNS(GetOutlookApp), olFolderInbox)
     ' assume there are inbox items
    For i = 1 To InboxItems.Count
        If TypeName(InboxItems.Item(i)) = "MailItem" Then ' it's an email
            Set thisEmail = InboxItems.Item(i)
            thisEmail.Display
            Sleep (5000) ' wait 5 seconds
            thisEmail.Close olDiscard
        End If
    Next i
End Sub
Function GetOutlookApp() As Outlook.Application
     ' returns reference to native Application object
    Set GetOutlookApp = Outlook.Application
End Function
Function GetNS(ByRef app As Outlook.Application) As Outlook.Namespace
    Set GetNS = app.GetNamespace("MAPI")
End Function
Function GetItems(olNS As Outlook.Namespace, folder As OlDefaultFolders) As Outlook.Items
    Set GetItems = olNS.GetDefaultFolder(folder).Items
End Function

上面提到的代码帮助我,但它会在5秒差异后打开所有邮件,但我真的只想一次打开一封邮件,当第一封邮件关闭时,下一封邮件会打开,邮件之间的差异可能是我10分钟或者可能是1小时所以请建议

如何从一封邮件转移到另一封邮件?

1 个答案:

答案 0 :(得分:0)

  

但我真的只想一次打开一封,第一封邮件关闭时,下一封邮件会打开

对代码进行细微更改应该可以解决问题

删除以下行

Sleep (5000) ' wait 5 seconds
thisEmail.Close olDiscard

True 旁边添加 .Display

实施例

For i = 1 To InboxItems.Count
    If TypeName(InboxItems.Item(i)) = "MailItem" Then ' it's an email
        Set thisEmail = InboxItems.Item(i)
        thisEmail.Display True
    End If
Next i

完成阅读后,只需关闭它,它就会打开下一个邮件项目

相关问题