2017-09-21 36 views
0

我有這個VBA代碼,我將它附加到規則中,以便它在到達時自動打印.pdf附件和電子郵件。是否可以添加一個標誌,如果它成功打印?將完整的標誌添加到電子郵件

  Private Declare Function ShellExecute Lib "shell32.dll" Alias _ 
       "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _ 
       ByVal lpFile As String, ByVal lpParameters As String, _ 
       ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 

      Sub PrintAttachments(oMail As Outlook.MailItem) 
       Dim colAtts As Outlook.Attachments 
       Dim oAtt As Outlook.Attachment 
       Dim sFile As String 
       Dim sDirectory As String 
       Dim sFileType As String 

       sDirectory = "C:\Users\USER\Desktop\PDFS\Print\" 

       Set colAtts = oMail.Attachments 

       If colAtts.Count Then 
       For Each oAtt In colAtts 

        sFileType = LCase$(Right$(oAtt.FileName, 4)) 

        Select Case sFileType 

      ' Add additional file types below followed by comma 
        Case ".pdf" 

        sFile = sDirectory & oAtt.FileName 
        oAtt.SaveAsFile sFile 
        oMail.PrintOut 
        ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0 
        End Select 
       Next 

       End If 

      End Sub 
+0

你使用哪種版本的Outlook? – DaBeau96

+0

我使用outlook 2013 – Xiodrade

回答

0

試試這個:

  If oMail.Categories <> "Printed" Then 
       Case ".pdf" 

       sFile = sDirectory & oAtt.FileName 
       oAtt.SaveAsFile sFile 
       oMail.PrintOut 
       oMail.Categories = "Printed" 
       oMail.Save 
       ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0 
       End Select 
       Next 
      Else 
       MsgBox "It was already printed" 
      End If 
+0

謝謝你試圖幫助我。不幸的是,這不是我需要做的。我原來的帖子只是要求添加一個標誌(或類別)以便在打印後使用。我的原始代碼是在郵件到達時執行的運行腳本規則。這段代碼會在一夜之間繼續運行,所以我不能使用簡單地在選擇中工作的代碼,只打印電子郵件。我提供的代碼打印出我需要的附件和電子郵件。我只需要幫助將標誌添加到我現有的代碼中。 – Xiodrade

+0

嘗試更新的代碼 – DaBeau96

+0

我結束了不得不移動它,所以它的工作,但我得到它的工作。謝謝! – Xiodrade