如何在当前代码中添加条件,如果电子邮件主题已在列中找到,则跳过该电子邮件
How do I add in my current code the condition where in if the email subject already found in a column, skip that email
我的代码如下。我只想要一个函数来跳过电子邮件主题,如果它已经在工作表中的话。我已经尝试了几件事,但没有奏效。如果您有后续问题,请在此处发表评论。 :(
If filteredItems.Count = 0 Then
Debug.Print "No emails found"
Found = False
Else
Found = True
For Each itm In filteredItems
'''
If Range("B" & Rows.Count).Value <> itm.ReceivedTime Then
Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Format(itm.ReceivedTime, "yyyymmdd")
Range("C" & Rows.Count).End(xlUp).Offset(1).Value = itm.Subject
Range("B" & Rows.Count).End(xlUp).Offset(1).Value = itm.ReceivedTime
Range("D" & Rows.Count).End(xlUp).Offset(1).Value = itm.SenderName
Range("H" & Rows.Count).End(xlUp).Offset(1).Value = itm.Body
Range("H:H").WrapText = False
Range("E" & Rows.Count).End(xlUp).Offset(1).Value = "Not Started"
'''
Debug.Print itm.Subject
End If
Next
End If
'If the subject isn't found:
If Not Found Then
MsgBox "No new ticket as of" & " " & Now() & "." & " " & "Please try again later."
Else
End If
使用 Worksheetfunction.Countif(Range("C:C"), "*" & itm.Subject & "*") > 0
作为支票。
此外,引用工作表变量也是最佳做法,例如
Dim Wksht as Worksheet
Set Wksht = Activeworkbook.Sheets("Sheet1")
If Wksht.Range(...
-- 如果您 select 另一个工作表中途运行,这将阻止您的代码受到影响。
我的代码如下。我只想要一个函数来跳过电子邮件主题,如果它已经在工作表中的话。我已经尝试了几件事,但没有奏效。如果您有后续问题,请在此处发表评论。 :(
If filteredItems.Count = 0 Then
Debug.Print "No emails found"
Found = False
Else
Found = True
For Each itm In filteredItems
'''
If Range("B" & Rows.Count).Value <> itm.ReceivedTime Then
Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Format(itm.ReceivedTime, "yyyymmdd")
Range("C" & Rows.Count).End(xlUp).Offset(1).Value = itm.Subject
Range("B" & Rows.Count).End(xlUp).Offset(1).Value = itm.ReceivedTime
Range("D" & Rows.Count).End(xlUp).Offset(1).Value = itm.SenderName
Range("H" & Rows.Count).End(xlUp).Offset(1).Value = itm.Body
Range("H:H").WrapText = False
Range("E" & Rows.Count).End(xlUp).Offset(1).Value = "Not Started"
'''
Debug.Print itm.Subject
End If
Next
End If
'If the subject isn't found:
If Not Found Then
MsgBox "No new ticket as of" & " " & Now() & "." & " " & "Please try again later."
Else
End If
使用 Worksheetfunction.Countif(Range("C:C"), "*" & itm.Subject & "*") > 0
作为支票。
此外,引用工作表变量也是最佳做法,例如
Dim Wksht as Worksheet
Set Wksht = Activeworkbook.Sheets("Sheet1")
If Wksht.Range(...
-- 如果您 select 另一个工作表中途运行,这将阻止您的代码受到影响。