按日期按顺序批量打印电子邮件附件

时间:2018-01-02 15:10:43

标签: vba email printing outlook outlook-vba

问题:

您好,我有一个宏,它可以节省我很多点击次数,但最终没有那么多时间,当它归结为它时。该代码允许我标记任何邮件文件夹中的所有内容。它将在电子邮件中打印附件。

此后错误开始。每当我按下此按钮时,项目就绪并准备就绪,以便与打印机竞争。这意味着首先到达打印机的任何附件是首先打印的附件。然后,我必须在打印完成后按顺序放置所有内容。

我目前的代码:

Sub BatchPrintAllAttachmentsinMultipleEmails()
    Dim objFileSystem As Object
    Dim strTempFolder As String
    Dim objSelection As Outlook.Selection
    Dim objItem As Object
    Dim objMail As Outlook.MailItem
    Dim objAttachments As Outlook.Attachments
    Dim objAttachment As Outlook.Attachment
    Dim objShell As Object
    Dim objTempFolder As Object
    Dim objTempFolderItem As Object
    Dim strFilePath As String

    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    strTempFolder = objFileSystem.GetSpecialFolder(2).Path & "\Temp for Attachments " & Format(Now, "YYYY-MM-DD_hh-mm-ss")
    'Create a new temp folder
    MkDir (strTempFolder)

    Set objSelection = Outlook.Application.ActiveExplorer.Selection

    For Each objItem In objSelection
        If TypeOf objItem Is MailItem Then
           Set objMail = objItem
           Set objAttachments = objMail.Attachments

           'Save all the attachments in the temp folder
           For Each objAttachment In objAttachments
               strFilePath = strTempFolder & "\" & objAttachment.FileName
               objAttachment.SaveAsFile (strFilePath)

               'Print all the files in the temp folder
               Set objShell = CreateObject("Shell.Application")
               Set objTempFolder = objShell.NameSpace(0)
               Set objTempFolderItem = objTempFolder.ParseName(strFilePath)
               objTempFolderItem.InvokeVerbEx ("print")
           Next objAttachment
        End If
    Next
End Sub

目标:

我希望代码能够查找日期,然后打印最早的日期,并为最新的日期工作。有没有机会,我可以放入一个字符串,让宏“冷却”并按顺序发送到打印机,从最旧的日期到最新的?

0 个答案:

没有答案