我想在活动电子邮件中替换" text1"用" text2" 。这是我的代码:
Sub Custmod()
Dim olItem As Outlook.MailItem
Dim objOL As Outlook.Application
Dim olOutMail As Outlook.MailItem
Dim sText As String
Dim vText As String
Dim strBody As String
Set objOL = Application
Set objItem = objOL.ActiveInspector.CurrentItem
For Each olItem In Application.ActiveExplorer.Selection
sText = olItem.body
vText = Split(sText, Chr(13))
For i = 1 To UBound(vText)
If InStr(1, vText(i), "TEXT1") Then
olItem.body = Replace(vText(i), "TEXT2", "")
Next i
End Sub
欢迎任何帮助。谢谢。
答案 0 :(得分:1)
看起来你正在尝试在不需要时使用数组。
替换适用于同一个单词的多个实例。
Option Explicit
Sub Custmod()
Dim olItem As mailItem
Set olItem = CreateItem(olMailItem)
olItem.body = "TEXT1" & Chr(13) & "Here is some stuff." & Chr(13) & "TEXT1 again."
olItem.Display
MsgBox olItem.body
olItem.body = Replace(olItem.body, "TEXT1", "TEXT2")
MsgBox olItem.body
Set olItem = Nothing
End Sub