我希望阅读我的Outlook收件箱,以了解今天收到的所有在主题中带有“取消警报”的电子邮件。
这些电子邮件的正文中有两行数据,每行6列。电子邮件正文如下所示
Record ID Date Name Date 2 Status Note
R-99864 06-20-2019 Fonsi 06-19-2019 Canceled Record was out of date range
我想提取记录ID并将其放入我的excel工作表中。
我可以通过搜索电子邮件主题来识别我的电子邮件。但是,我不知道如何提取记录ID。
您能告诉我如何使用Excel VBA提取记录ID吗?
下面是我根据电子邮件主题确定我的电子邮件的代码。
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myitems As Outlook.Items
Dim myitem As Object
Dim Found As Boolean
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myitems = myInbox.Items
Found = False
For Each myitem In myitems
If myitem.Class = olMail Then
If InStr(1, myitem.Subject, "Cancel Alert") > 0 Then
Debug.Print "Found"
MsgBox (myitem.Subject)
Found = True
End If
End If
Next myitem
'If the subject isn't found:
If Not Found Then
NoResults.Show
End If
'myOlApp.Quit
Set myOlApp = Nothing
End Sub