rollingzep
Board Regular
- Joined
- Nov 18, 2013
- Messages
- 224
- Office Version
- 365
- Platform
- Windows
Hi,
I have posted this question in another forum as well,
<p>
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?</p>
I have posted this question in another forum as well,
Move Mails from Inbox to Archive
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...
www.vbaexpress.com
<p>
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?</p>
VBA 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
[B] Set objDestfolder = MYFOLDER.Folders("Archive_Proc")[/B]
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 MYFOLDER = Nothing
Set OlMail = Nothing
Set OlItems = Nothing
Set olApp = Nothing
Srt objDestfolder = Nothing