Count Read and Unread Emails date wise for shared mailbox

点点圈 提交于 2019-12-13 01:33:35

问题


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.

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    

回答1:


Try:

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

Where you put the correct folder name in there.



来源:https://stackoverflow.com/questions/36583378/count-read-and-unread-emails-date-wise-for-shared-mailbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!