1

我有以下代码

Sub RemoveInvalidChar(myMail As MailItem)


If myMail.Subject <> vbNullString Then
        strname = myMail.Subject
   Else

End If
strname = Replace(strname, "&", "and")

End Sub

基本上我想用单词替换 & char 并使用规则。似乎不起作用。

4

3 回答 3

1

您尚未将 myMail.Subject 设置为新字符串。添加以下行:

myMail.Subject = strname 

但请确保您发送的是myMailByRef。

于 2013-08-22T10:32:11.283 回答
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

如果这不起作用,请添加断点并确保您实际上是通过规则正确调用宏。

于 2013-08-22T13:48:48.417 回答
0

enderland - 我昨天设法得到答案,但无法发布结果。

我错过了 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
于 2013-08-23T13:30:03.717 回答