简体   繁体   English

自动化 Outlook 邮件调度程序

[英]Automate Outlook mail scheduler

I came across a code in Excel VBA which sends mail via Outlook based on given time ranges in the code.我在 Excel VBA 中遇到了一个代码,它根据代码中的给定时间范围通过 Outlook 发送邮件。 The "TO, CC, Subject and Mail Body" are all input in excel only.仅在 excel 中输入“收件人、抄送、主题和邮件正文”。

The code works fine but .Send giving error 287-Application or object defined error .该代码工作正常,但.Send给出错误287-Application or object defined error The code works well in my colleague's laptop, so I am guessing it is some setting error in my outlook or excel.该代码在我同事的笔记本电脑上运行良好,所以我猜这是我的 outlook 或 excel 中的一些设置错误。 I keep my outlook open while executing the code.在执行代码时,我让我的 outlook 保持打开状态。 The code is written below.代码写在下面。 Can anyone point to what might be wrong?谁能指出可能出了什么问题?

Sub Send_Email()
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets("Sheet1")
    
    '''''''''' Update Next ''''''''''''''

    Call Update_Next_Schedule_Time
    Application.OnTime sh.Range("K20").Value, "Send_Email"

    ''''''''''''''''''''''''''''''''''''''
    Dim oa As Object
    Dim msg As Object

    Set oa = CreateObject("outlook.application")
    Set msg = oa.createitem(0)

    With msg
        .To = sh.Range("C2").Value
        .CC = sh.Range("C4").Value
        .Subject = sh.Range("C6").Value
        .Body = sh.Range("C8").Value
        .display
        .send
    End With
End Sub

I believe this is due to your Outlook security policy.我相信这是由于您的 Outlook 安全策略。 Check if it allows programmatic access.检查它是否允许编程访问。 If not, and you cannot convince your IT department to make any change, then you should automate the opened outlook app rather that creating a new Outlook instance.如果没有,并且您无法说服您的 IT 部门进行任何更改,那么您应该自动化打开的 outlook 应用程序,而不是创建一个新的 Outlook 实例。 Also, are you trying to send the email to yourself, by any chance?另外,您是否尝试将 email 发送给自己?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM