阅读背景:

收到的电子邮件日期从outlook。格式和在单元格中搜索的问题。

来源:互联网 
Sub ReceivedEmailDate()
Dim outlookApp
Dim olNs As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder
Dim olMail As Variant
Dim myTasks
Dim sir() As String

Set outlookApp = CreateObject("Outlook.Application")

Set olNs = outlookApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set myTasks = Fldr.Items

i = 2             'This is the row you want the date/time to start from

For Each olMail In myTasks

                'This is where the search occurs in the outlook inbox (parameters can be altered depending on what you want to search for)
                'I have stated to search for the invoice numbers in the subject field of the email. Invoice numbers located down column E
If (InStr(1, olMail.Subject, ActiveSheet.Cells(i, 5), vbTextCompare) > 0) Then
  ActiveSheet.Cells(i, 8).Value = Format(olMail.ReceivedTime, "DD/MM/YY")      'format function to only show the date, rather than both date and time


  i = i + 1     'Count so that each email date/time is entered in the row below the previous one

End If

Next olMail

Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing

End Sub
Sub ReceivedEmailDate()
Dim outlookApp
Dim olNs



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: