Send method not working when using Word Editor

允我心安 提交于 2019-12-12 01:47:08

问题


I have a rule that whenever I receive an email with a specific word in a subject line, it will trigger this script.

The script will forward the email to the specific user in the subject line and use the word editor to delete the first line of the email body and change it to "Hi,".

When I use .Display method then manually click send it is working fine, but whenever I use .Send method, the outlook won't update/receive the email in the mailbox and won't forward the edited email. I need to close/relaunch outlook for the script to trigger again.

What is wrong in the script?

Sub EmailForward(item As Outlook.MailItem)

    Dim body As String
    Dim MI As MailItem
    Dim oMail As Outlook.MailItem

    Dim olInsp As Outlook.Inspector
    Dim wdDoc As Object
    Dim oRng As Object
    Dim objSel As Word.Selection

    Dim olApp As Outlook.Application

    Set MI = item
    Set olApp = Outlook.Application

        item.Subject = Replace(item.Subject, ", 4 - Low, Open", "")
        item.Subject = Replace(item.Subject, ", 4 - Low, New", "")
        item.Save

        Eadd = Right(MI.Subject, Len(MI.Subject) - InStr(MI.Subject, "|"))

        Set oMail = MI.Forward

        oMail.Subject = MI.Subject
        oMail.To = Eadd
        oMail.HTMLBody = item.HTMLBody

            Set olInsp = oMail.GetInspector
            Set wdDoc = olInsp.WordEditor
            Set oRng = wdDoc.Range(0, 0)
            Set objSel = wdDoc.Windows(1).Selection
            'oRng.Text = "The accompanying message text"

            objSel.MoveDown wdLine, 1, wdExtend
            objSel.Delete wdCharacter, 1
            objSel.TypeText Text:="Hi,"
            objSel.TypeParagraph

        oMail.SendUsingAccount = olApp.Session.Accounts.item(1)
        oMail.Display
        oMail.Save
        oMail.Send

End Sub

回答1:


That's a known issue in Outlook. You have to call the Display method first to get the inspector visible.

Use the HTMLBody or Body property to modify the message body on the fly.



来源:https://stackoverflow.com/questions/30127341/send-method-not-working-when-using-word-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!