Excel VBA代码仅在Outlook可见时才有效

时间:2012-05-25 00:28:01

标签: vba outlook

Set OutApp = CreateObject("Outlook.Application")
MsgBox (OutApp Is Nothing)

On Error GoTo errorHandler
Set OutMail = OutApp.CreateItem(0)
        'OutMail.Parent.Display '****
        On Error Resume Next
        With OutMail
            .To = cell.Value
            .Subject = "Subject"
            .Body = "Body"
            .Se
        End With
        On Error GoTo errorHandler
        Set OutMail = Nothing

如果我想要发送电子邮件,我必须取消注释OutMail.Parent.Display行。我为什么要通过让Outlook可见来惹恼用户呢?这是安全设置还是什么?

1 个答案:

答案 0 :(得分:0)

不,没有必要:)另外我猜.Se是问题中提到的代码中的拼写错误?

这适合我。

Option Explicit

Sub Sample()
    Dim OutApp As Object, OutMail As Object

    On Error GoTo Whoa

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With OutMail
        .To = cell.Value
        .Subject = "Subject"
        .Body = "Body"

        .Send '<~~ .Display to display
    End With

LetsContinue:
    Set OutMail = Nothing
    Set OutApp = Nothing
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume LetsContinue
End Sub