明智地计算共享邮箱的已读和未读电子邮件日期 [英] Count Read and Unread Emails date wise for shared mailbox

查看:115
本文介绍了明智地计算共享邮箱的已读和未读电子邮件日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编辑了我在Stack Overflow中找到的VBA以适合我的需求.

I have edited VBA which I found in Stack Overflow to suit my needs.

它为我提供了默认收件箱日期的电子邮件计数和没有日期的未读电子邮件计数.

It gives me the count of emails of my default inbox date wise and count of unread emails without dates.

我需要它来计算共享邮箱的电子邮件.例如Redstreamattmail,而不是默认邮箱,DATE WISE表示整体电子邮件和未读电子邮件.

I need it to count the emails of my shared mailbox. For example Redstreamattmail and not the default mailbox, DATE WISE for overall emails and unread emails.

Sub HowManyEmails()    

Dim objOutlook As Object, objnSpace As Object, objFolder As MAPIFolder    
Dim EmailCount As Integer    

Dim a As Outlook.Application    
Dim b As Outlook.NameSpace    
Dim c As Outlook.MAPIFolder    

Set a = New Outlook.Application    
Set b = a.GetNamespace("MAPI")    
Set c = b.GetDefaultFolder(olFolderInbox)    
d = c.UnReadItemCount    

Set objOutlook = CreateObject("Outlook.Application")    
Set objnSpace = objOutlook.GetNamespace("MAPI")    

On Error Resume Next    

Set objFolder = objnSpace.GetDefaultFolder(olFolderInbox)    

If Err.Number <> 0 Then    
    Err.Clear    
    MsgBox "No such folder."    
    Exit Sub    
End If    

EmailCount = objFolder.Items.Count    

MsgBox "Number of emails in the folder: " & EmailCount & " Total Unread     email count are   " & d    

Dim dateStr As String    
Dim myItems As Outlook.Items    
Dim dict As Object    
Dim msg, msg1 As String    

Set dict = CreateObject("Scripting.Dictionary")    
Set myItems = objFolder.Items    

myItems.SetColumns ("SentOn")    

' Determine date of each message:    

For Each myItem In myItems    
    dateStr = GetDate(myItem.SentOn)    
    If Not dict.Exists(dateStr) Then    
        dict(dateStr) = 0    
    End If    
    dict(dateStr) = CLng(dict(dateStr)) + 1    
Next myItem    

' Output counts per day:    
For Each o In dict.Keys    
    msg = msg & o & ":    " & dict(o) & " Email items" & vbCrLf    
Next    
msg1 = "unread Emails are        " & d    

Set objFolder = Nothing    
Set objnSpace = Nothing    
Set objOutlook = Nothing    

'Send Email    
Set OutApp = CreateObject("outlook.Application")    
Set OutMail = OutApp.CreateItem(o)    

With OutMail    
    .Subject = "Count of emails"    
    .To = "name@company.com;"    
    .Body = msg & msg1    
    .Display    
    '.Send    
End With     

Set OutMail = Nothing    
Set OutApp = Nothing    

End Sub    

推荐答案

尝试:

Set c =  b.Folders("Name of shared mailbox")

在其中放置正确的文件夹名称的地方.

Where you put the correct folder name in there.

这篇关于明智地计算共享邮箱的已读和未读电子邮件日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆