【问题标题】:Resend emails stuck in Outbox重新发送卡在发件箱中的电子邮件
【发布时间】:2021-08-23 21:53:23
【问题描述】:

我在网上找到了一个脚本,用于重新发送卡在 Outlook 365 发件箱中的电子邮件。它要求我选择电子邮件。

我有两个帐户,包括一个 Microsoft Exchange 帐户。有什么办法可以修改这个宏,这样当我在 Microsoft Exchange 帐户中发送电子邮件时,所有可能卡在发件箱中的电子邮件都会被自动选中并运行以下宏?

Sub BatchResendEmails()
    Dim objSelection As Outlook.Selection
    Dim objMail As Outlook.MailItem
    Dim objInspector As Outlook.Inspector
    Dim objResendMail As Outlook.MailItem

    Set objSelection = Application.ActiveExplorer.Selection
 
    If Not (objSelection Is Nothing) Then
        On Error Resume Next
        For Each objMail In objSelection
            objMail.Display
            Set objInspector = myItem.GetInspector
 
            'Resend message
            objInspector.CommandBars.ExecuteMso ("ResendThisMessage")
  
            Set objResendMail = Application.ActiveInspector.CurrentItem
 
            'You can change the email details as per your needs
            With objResendMail
                .Subject = objMail.Subject
                .Send
            End With
 
            objMail.Close olDiscard
        Next
    End If
End Sub

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    在我的头顶:

        Sub BatchResendEmails()
        Dim objFolder As Outlook.MAPIFolder
        Dim objMail As Outlook.MailItem
        Dim objInspector As Outlook.Inspector
        Dim objResendMail As Outlook.MailItem
    
        Set objFolder = Application.Session.GetDefaultFolder(olFolderOutbox)
     
           On Error Resume Next
           For Each objMail In objFolder.Items
               objMail.Display
               Set objInspector = myItem.GetInspector
     
               'Resend message
               objInspector.CommandBars.ExecuteMso ("ResendThisMessage")
      
               Set objResendMail = Application.ActiveInspector.CurrentItem
     
               'You can change the email details as per your needs
               With objResendMail
                   .Subject = objMail.Subject
                   .Send
               End With
     
               objMail.Close olDiscard
           Next
    End Sub
    

    【讨论】:

    • 谢谢,但它返回运行时错误 '438" 对象不支持此属性或方法
    • 查看上面的变化
    • 谢谢。当我手动运行脚本时它可以工作。但是,当我在 Exchange 帐户中发送电子邮件时,是否可以自动运行此脚本?
    • 更具体地说,我希望这个脚本在我单击 Exchange 帐户中的发送按钮时自动运行。谢谢。
    • 另外,我想使用 Windows 任务计划程序或运行批处理文件来安排脚本定期运行(即每 5 分钟一次)。感谢您的帮助。
    【解决方案2】:

    要删除文件夹的手动选择,请设置对文件夹 https://docs.microsoft.com/en-us/office/vba/api/outlook.namespace.getdefaultfolder 的引用。

    删除手动选择项目Iterate all email items in a specific Outlook folder
    减少发件箱For Each loop: Some items get skipped when looping through Outlook mailbox to delete items 中的项目数时,您可能需要反向循环。

    定期运行代码Outlook VBA - Run a code every half an hour

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-25
      • 1970-01-01
      • 2021-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      相关资源
      最近更新 更多