最近我的公司开始添加有关来自我公司外部的电子邮件的警告。
“此电子邮件来自 ***** 组外部。除非您认识发件人并知道内容安全,否则请勿单击链接或打开附件。 这是外部寄来的邮件,点击链接或打开附件前请停、看、听。”
通常情况下我对此不会介意,但当我 90% 的电子邮件来自外部时,这会变得很烦人,尤其是当它来自我已经接触多年的另一家公司时。
我找到了一个可以删除警告句子的宏,但我无法让它删除中文句子。当谈到 VBA 时,我是一个超级新手,虽然我可以在谷歌和逻辑的帮助下做一些基本的事情,但我几乎不理解我提取的这段代码。我也尝试过将中文句子添加到InStr中,但它只是显示为???。尝试将“非 Unicode 程序的语言”更改为中文(简体,中国),但宏就停止工作了。
这是我正在使用的宏:
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(), "")