0
특정 값이 포함 된 이메일을 수신하고 특정 폴더로 이메일을 이동시킬 때마다 로그 파일 (텍스트)을 만듭니다. 이 코드는 한 전자 메일 보낸 사람에게 적용되며 다른 전자 메일 사용자가 같은 제목으로 보낼 때 작동하지 않습니다. 그 의도는 비슷한 주제의 이메일을 보내는 사람은 코드에 의해 처리되어야한다는 것입니다.다른 발신자가 작동하지 않는 코드
다음은 ThisOutlookSession의 코드입니다.
Option Explicit
Private WithEvents olInboxItems As Items
Private Sub Application_Startup()
Set olInboxItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Dim olMailItem As MailItem
Dim strAttachmentName As String
If TypeOf Item Is MailItem Then
Set olMailItem = Item
If olMailItem.Attachments.Count = 0 _
And InStr(olMailItem.Subject, "Exception Noted at FTD") > 0 Then
'Create LogFile to a network folder
Dim strFile_Path As String
strFile_Path = "\\10.53.66.30\cbd\Status\" & olMailItem.SenderName + "StaffLogfile.txt"
Open strFile_Path For Append As #1
Write #1, Format(olMailItem.ReceivedTime, "dd-mmm-yyyy | hh:mm | ") + olMailItem.SenderName + " | " + olMailItem.Subject
Close #1
End If
'Move to Exception Folder
Dim fldr As Outlook.MAPIFolder
If olMailItem.Attachments.Count = 0 _
And InStr(olMailItem.Subject, "Exception Noted at FTD") > 0 Then
Set fldr = Outlook.Session.Folders("Archives").Folders("Personal Folder").Folders("FTD").Folders("Exception Report")
olMailItem.Move fldr
End If
End If
End Sub
On Error Resume Next없이 실행 해 볼 수 있습니까? 오류가 있습니까? – Shmukko
오류가 전혀 발생하지 않습니다. 한 번의 발신자는 완벽하게 작동하지만 다른 발신자와 함께 로그 파일을 만들거나 전자 메일을 원하는 폴더로 옮기지 않습니다. 단지받은 편지함에 남아 있습니다. –
오류가 발생한 On Error Resume을 제거하십시오. 다음으로 결과를 얻은 다음 AndStr (UCase (olMailItem.Subject), UCase (FTD에서 Exception Noted))> 0을 입력 한 다음 – niton