Save all attachments macro from certain folder and move processed e-mail to another folder VBA outlook

jaryszek

Board Regular
Joined
Jul 1, 2016
Messages
213
Hello,

this is a crossed post from:

https://www.excelforum.com/outlook-...-move-processed-e-mail-to-another-folder.html

There is no reply so maybe here i will find the answer.


I would like to ask you about my macro.


Macro is working very good - saving all atachments from new e-mails in folder "FolderTest" and next macro is moving processed e-mail to folder "processed".


My macro code:

Code:
Public WithEvents FolderItems As Outlook.Items


Private Sub Application_Startup()
   Set FolderItems = Session.GetDefaultFolder(olFolderInbox).Folders("FolderTest").Items
End Sub


Private Sub FolderItems_ItemAdd(ByVal Item As Object)
    On Error Resume Next


Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String


Dim myDestFolder As Outlook.Folder
Set myDestFolder = Outlook.Session.GetDefaultFolder(olFolderInbox).Folders("FolderTest").Folders("processed")


sSaveFolder = "C:\temp"


For Each oAttachment In Item.Attachments
    If oAttachment.DisplayName Like "*.doc" Then
        oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
    End If
Next


Item.Move myDestFolder


End Sub

I am wondering why saving is working only once. When I am reciving e-mail and moving it to folder "FolderTest" macro is working fine (attachments are saved and e-mail is moved to "processed" folder.
Problem is when i am returning e-mail to inbox at all and try to move it once again to "FolderTest".
Macro is running normally, even e-mail is moved to folder "processed" but attachments are not saved...


Why this is working like that?


Please Help,
Jacek Antek
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I suggest you comment out the On Error Resume Next line in the ItemAdd event since all it's doing is masking any errors that may occur. Are you deleting the attachments from the first save when you try to reuse the same item?
 
Upvote 0
Hi RoryA. Thank you for your help and support.

I delete on error resume next and... it is working like a charm !

I do not now why...

Thank you !

Jacek
 
Upvote 0

Forum statistics

Threads
1,223,793
Messages
6,174,635
Members
452,575
Latest member
Fstick546

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top