【发布时间】:2019-09-05 17:20:20
【问题描述】:
我有一个程序可以找到某个字符串并将其删除。
这是通过Replace() 完成的。
但是,当收到的邮件是 HTML 而不是纯文本时,大多数 HTML 功能都会被破坏,并且邮件是纯文本加上超链接。
因此很明显,我的程序除了字符串之外还杀死了一些东西。
这是我的程序:
Public Sub EditBodyCgReplace()
'Declarations
Dim obj As Object
Dim Sel As Outlook.Selection
Dim DoSave As Boolean
Dim NewBody As String
Dim strDelete01 As String
Dim strDelete02 As String
Dim strDelete03 As String
'Fill the variables
strDelete01 = "Diese E-Mail kommt von Personen außerhalb der Stadtverwaltung. Klicken Sie nur auf Links oder Dateianhänge, wenn Sie die Personen für vertrauenswürdig halten."
strDelete02 = "################################################################################"
'Work with it
If TypeOf Application.ActiveWindow Is Outlook.Inspector Then
Set obj = Application.ActiveInspector.CurrentItem
Else
Set Sel = Application.ActiveExplorer.Selection
If Sel.Count Then
Set obj = Sel(1)
DoSave = True
End If
End If
If Not obj Is Nothing Then
NewBody = Replace(obj.Body, strDelete01, "")
NewBody = Replace(obj.Body, strDelete02, "")
If NewBody <> "" Then
obj.Body = NewBody
If DoSave Then
obj.Save
End If
End If
End If
End Sub
我该怎么做才能使这个(或类似的)过程杀死字符串但不损害电子邮件的 HTML 结构,从而使其在屏幕上的视觉特征得以保留?
【问题讨论】: