简体   繁体   中英

Outlook VBA code to extract attachment from emails and save them to a separate folder in Outlook

Please if anyone could help it would be great, I need to create a macro that will enable me to pull out attachments(outlook emails) from selected emails with "X" in their title. Then I will need to save these attachments into a folder within outlook. Would this be possible? Any advice would be really appreciated!

Use the Attachment.SaveAsFile method to save the attachment to the specified path.

to pull out attachments(outlook emails) from selected emails with "X" in their title.

It is not clear what the title in Outlook stands for, but I suppose you are talking about the Subject line. The Explorer.Selection property returns a Selection object that contains the item or items that are selected in the explorer window. For example, here is how you can get the selected items in the Explorer window:

Sub GetSelectedItems() 
 Dim myOlExp As Outlook.Explorer 
 Dim myOlSel As Outlook.Selection
 Dim mySender As Outlook.AddressEntry 
 Dim oMail As Outlook.MailItem 
 
 Dim x As Long 
 
 Set myOlExp = Application.ActiveExplorer  
 Set myOlSel = myOlExp.Selection  
 For x = 1 To myOlSel.Count  
   If InStr(1, myOlSel.Item(x).Subject, "X") <> 0 Then  
     Set oMail = myOlSel.Item(x)    
   End If  
 Next x 
 
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM