我想比较Outlook电子邮件中的主题行,基本上只是一个六位数的数字,并将相同的数字与现有的excel列匹配,并在同一行的不同单元格上标记为已完成。 例如,如果我从主题为123456的Outlook发送电子邮件,则代码应在excel列上找到编号为123456的列,并自动在存在123456的同一行上将其标记为已完成。 如果有人可以帮助我提供代码,我将不胜感激。
答案 0 :(得分:0)
为此,首先需要获取“发件人姓名”列表,请使用以下代码: (此代码摘自一个名为PatricK的人的另一篇文章)
Sub GetFromInbox()
Const olFolderInbox = 6
Dim olApp As Object, olNs As Object
Dim oRootFldr As Object
Dim lCalcMode As Long
Dim oItem As Object
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set oRootFldr = olNs.GetDefaultFolder(olFolderInbox) '.Folders("Inbox")
For Each oItem In oRootFldr.Items
If TypeName(oItem) = "MailItem" Then
With oItem
SearchNBR (.SenderName)
lrow = lrow + 1
End With
End If
Next
Set oRootFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
收到发件人邮件后,在所需的标签上搜索并标记为绿色!
Private Sub SearchNBR(NBR)
Dim rgFound As Range
On error resume next
'Search on the Sheet and range you want!
Set rgFound = Range("A1:A1000").Find(NBR)
'It will mark the Sender name in colour green
rgFound.Interior.Color = vbGreen
End Sub
我希望这对您有用!!!! 干杯!