我的公司添加了有关来自我公司外部的电子邮件的警告。
此电子邮件来自 ***** 群组外部。除非您认识发件人并且知道内容是安全的,否则请勿单击链接或打开附件。
这是外部寄来的邮件,点击链接或打开附件前请停、看、听。
我找到了一个可以删除警告句子的宏,但我无法让它删除中文句子。
我尝试将中文句子添加到
InStr
中,但它显示为???.Option Explicit
Sub myRuleMacro(item As Outlook.MailItem)
Sub RemoveExpressionFOLDER()
Dim outFldr As Folder
Dim outItems As Items
Dim outMailItem As MailItem
Dim i As Long
Dim cleanCount As Long
Set outFldr = ActiveExplorer.CurrentFolder
Set outItems = outFldr.Items
For i = 1 To outItems.Count
If outItems(i).Class = olMail Then
Set outMailItem = outItems(i)
With outMailItem
'Debug.Print .Subject
If InStr(.Body, "This email originated from outside of ***** group. Do not click links or open attachments unless you recognize the sender and know the content is safe.") Then
If .BodyFormat = olFormatHTML Then
.HTMLBody = Replace(.HTMLBody, "This email originated from outside of ***** group. Do not click links or open attachments unless you recognize the sender and know the content is safe.", "")
Else
.Body = Replace(.Body, "This email originated from outside of ***** group. Do not click links or open attachments unless you recognize the sender and know the content is safe.", "")
End If
.Save
cleanCount = cleanCount + 1
End If
End With
End If
Next i
MsgBox (cleanCount & " mailitems cleaned.")
End Sub
有没有另一种方法可以将中文句子添加到我的
InStr
中,以便它可以删除这两个句子。或者,如果这是不可能的,也许另一个宏可以实现我的目标。
这是一种暴力硬编码方法……
中文字符存储为Unicode。您可以使用
ChrW
函数将整数转换为 Unicode,并使用 AscW
将 Unicode 字符转换为其整数值
因此,运行一个循环将每个字符一一转换为整数,并将它们聚合成一个相反的函数,我得到了:
Function ChineseWarning() AS String
ChineseWarning = ChrW(-28647) & ChrW(26159) & ChrW(22806) & ChrW(-28440) & _
ChrW(23492) & ChrW(20358) & ChrW(30340) & ChrW(-28427) & _
ChrW(20214) & ChrW(-244) & ChrW(-24866) & ChrW(25802) & _
ChrW(-28637) & ChrW(32080) & ChrW(25110) & ChrW(-27253) & _
ChrW(21855) & ChrW(-27068) & ChrW(20214) & ChrW(21069) & _
ChrW(-30005) & ChrW(20572) & ChrW(12289) & ChrW(30475) & _
ChrW(12289) & ChrW(-32643) & ChrW(12290)
End Function
然后您可以在您的
Replace
中使用它:
.HTMLBody = Replace(.HTMLBody, ChineseWarning(), "")
Function RemoveStr(ByVal inputText As String) As String
Dim regExp As Object, sWord As String
sWord = "This email originated from outside of ***** group. " & _
"Do not click links or open attachments unless you " & _
"recognize the sender and know the content is safe."
inputText = Replace(inputText, "")
Set regExp = CreateObject("VBScript.RegExp")
regExp.Pattern = "[\u4E00-\u9FA5\uFF0C\u3001\u3002]+"
RemoveStr = regExp.Replace(inputText, "")
End Function
If .BodyFormat = olFormatHTML Then
.HTMLBody = RemoveStr(.HTMLBody)
Else
.Body = RemoveStr(.Body)
End If