2016-06-18 10 views
2

Dieses Stück Code ist ein bisschen rau, aber es ist nur ein Mock-up. Was es Grund tut, ist:Outlook Antwort dann Mail löschen Artikel

Wenn eine E-Mail in meiner E-Mail kommt und die Betreffzeile beginnt mit ‚Partie‘:

  • Kopien E-Mail in einem anderen Ordner
  • Antworten
  • löscht Original per E-Mail E-Mail

Im Moment ist alles tun, was ich will, abgesehen von löschen Sie die E-Mail am Ende. Nachdem ich auf die E-Mail geantwortet habe und scheinbar das ursprüngliche E-Mail-Objekt nicht mehr erreichen kann, lösche ich es. Ich weiß, dass es etwas einfacher sein wird, aber ich kann es nicht sehen .....

Sub Check_For_Ticket(MyMail As MailItem) 
Dim mysubject As String 
Dim strEmail As String 

'On Error GoTo Ticketerror 

myemail = "pb***********@hotmail.com" 
mysubject = "Batch*" 

strEmail = MyMail.SenderEmailAddress 
strSubject = MyMail.Subject 
If strEmail = myemail And strSubject Like mysubject Then 
    MsgBox "yes" & strSubject 
    Call pbMoveMessageToTestFolder(MyMail) 
    Call AutoReply(MyMail) 
Else 
    MsgBox "no" & strSubject 
End If 

MsgBox "this email is: " & strSubject 
'Ticketerror: 
' MsgBox "There is an error " 
' MsgBox Err.Number & " : " & Err.Description 
End Sub 
Sub pbMoveMessageToTestFolder(MyMail As MailItem) 

' Works on one selected item 

    Dim myNameSpace As Outlook.NameSpace 
    Dim myInbox As Outlook.Folder 
    Dim myDestFolder As Outlook.Folder 
    Dim myItem As Object 
    Dim objcopy As Object 

     MsgBox "into 2nd sub" 

    Set myNameSpace = Application.GetNamespace("MAPI") 
    Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) 

    ' Add As many .Folders("SubfolderName") as needed 
    Set myDestFolder = myInbox.Folders("To_Process") 
    Set myItem = MyMail 
    'Application.ActiveExplorer.Selection.Item (1) 

    Dim copy As Object 
    Set copy = myItem.copy 
    'move copy to folder 
    copy.Move myDestFolder 

     MsgBox "should of copied" 

    Set myNameSpace = Nothing 
    Set myInbox = Nothing 
    Set myDestFolder = Nothing 
    Set myItem = Nothing 

End Sub 
Sub AutoReply(olItem As Outlook.MailItem) 
'declaring variables 
Dim olOutMail As Outlook.MailItem 
Dim olOutMail2 As Outlook.MailItem 
Dim strpbsubject As String 
Dim strSubject As String 
Dim Str As String 

Str = olItem.Subject 

MsgBox "3rd sub - subject: " & Str 

strpbsubject = "This is an auto-reply from ***, confirming that " & strMid & " has been successfully received at " & Format(DateTime.Now, "dd-MM-yyyy hh:mm:ss") 


'Creating the reply email 

    With olItem 
     Set olOutMail2 = olItem.Reply 
     With olOutMail2 
      .Body = strpbsubject 'Placing the body of the email in place 
      .Subject = "Delivered: " & Str 'appending "Delivered" to the subject line 
      .Send  ' This is a changeable variable to display the reply change to .Display 
         ' to deliver the response change to .Send 
      .UnRead = True 'makes the email unread after the auto response is sent 
     End With 
    Set olOutMail2 = Nothing 



    End With 

End Sub 

Antwort

0

Try MyMail.Delete nach Call AutoReply(MyMail)

If strEmail = myEmail And mysubject Like mysubject Then 
    MsgBox "yes" & mysubject 
    Call pbMoveMessageToTestFolder(MyMail) 
    Call AutoReply(MyMail) 
    MyMail.Delete 
Else 
+0

Dank Zugabe werde ich versuchen, dass und komme morgen wieder mit einem Update, wie ich sicher bin, dass es nicht funktioniert, wenn ich es letztes Mal versuchte. Wie auch immer, ich dachte, würde ich das E-Mail-Objekt einfach in den gelöschten Ordner verschieben? Dann lief ein Makro, das den gelöschten Ordner löschte? – Paul

+0

@Paul MyMail.Delete verschiebt das Element in den gelöschten Ordner – 0m3r

+1

Dank Om3r, endlich hat es funktioniert heute Nachmittag, werde ich den Code morgen veröffentlichen. Aber noch eine kurze Frage. Wenn Sie direkt auf der Seite des Codes, wo ich die E-Mail-Adresse festlegen. Ich mache es in der ersten Unterroutine. Ich möchte das wirklich in eine eigene Routine aufteilen. Ich dachte, dass ich es in den globalen Variablen tun könnte, aber das funktioniert nicht, müsste ich sie in einer öffentlichen Funktion delayen (möchte wirklich das myemail & mysubject)? – Paul

Verwandte Themen