Hi All,
This is a requirement of an existing code. The below code works and saves the attachment and also marks the read mails as Processed.
But I need to move these Processed mails from the Inbox to the folder, Archive_Proc. I am trying to Set the folder, objDestfolder as the destination folder for these processed mails to be moved. But I am getting object not found error (bolded line).
How to fix the code?
Dim olApp As Object Dim MYFOLDER As Object Dim OlItems As Object Dim olMail As Object Dim x As Integer Dim subject As String Dim strFile As String Dim strFolderpath As String Dim objDestfolder As Object Dim mychar As Object Dim sreplace As String Set olApp = GetObject(, "Outlook.Application") If Err.Number = 429 Then Set olApp = CreateObject("Outlook.Application") End If strFolderpath = "C:\Users\Testing" 'On Error Resume Next ' Set the Attachment folder. strFolderpath = strFolderpath & "\Attachments\" Set MYFOLDER = olApp.GetNamespace("MAPI").Folders("WeeklyProceedings Mailbox").Folders("Inbox") Set OlItems = MYFOLDER.Items For Each olMail In OlItems If olMail.subject Like "*Proceeding ID*" Then strFile = olMail & ".XML" strFile = strFolderpath & strFile If olMail.Attachments.Count > 0 Then For x = 1 To olMail.Attachments.Count olMail.Attachments.Item(x).SaveAsFile strFile Next x subject = olMail.subject sreplace = "_" subject = Replace(subject, " ", sreplace) olMail.Body = olMail.Body & vbCrLf & "The file was processed " & Now() olMail.subject = "Processed - " & subject 'olMail.Move objDestfolder olMail.Save End If End If Next Set objDestfolder = olApp.GetNamespace("MAPI").Folders("WeeklyProceedings Mailbox").Folders("Archive_Proc") olMail.Move objDestfolder Set MYFOLDER = Nothing Set OlMail = Nothing Set OlItems = Nothing Set olApp = Nothing Srt objDestfolder = Nothing