我有以下代码
Sub RemoveInvalidChar(myMail As MailItem)
If myMail.Subject <> vbNullString Then
strname = myMail.Subject
Else
End If
strname = Replace(strname, "&", "and")
End Sub
基本上我想替换&amp;使用单词和使用规则的char。似乎不起作用。
答案 0 :(得分:1)
您尚未将myMail.Subject设置为新字符串。添加以下行:
myMail.Subject = strname
但请确保您发送myMail
ByRef。
答案 1 :(得分:0)
Sub RemoveInvalidChar(myMail As MailItem)
If myMail.Subject <> vbNullString Then
'set the actual subject to a new subject
myMail.Subject= Replace(myMail.Subject, "&", "and")
'get in the habit of saving email when you change it via vba
'as there will be a lot of cases where you get burned for this
myMail.Save
End If
End Sub
如果这不起作用,请添加断点并确保您实际通过规则正确调用宏。
答案 2 :(得分:0)
我错过了mymail.save
无论如何,我的代码在下面,它的工作原理。 Ltrim只是从主题行的前面删除任何前面的空格。
Sub RemoveInvalidChar(myMail As MailItem)
Dim strname As String
Dim sreplace As String
sreplace = "and"
strname = LTrim(myMail.Subject)
strname = Replace(strname, "&", sreplace)
myMail.Subject = strname
myMail.Save
End Sub