I have a macro which helps me download the email attachments from outlook based on the list of the email subject lines listed in excel worksheet. Below are changes which i want to make to this macro.
• Define the outlook inbox, actually I want the macro to search the common team shared mailbox instead of personal mailbox
• Define the Save as folder path from a excel cell instead of hard coding the path in the macro
• Define the subject line's only unique part not the entire subject line since it consists of date and some code which changes daily so we can't hard code subject line
• Once the attachment is downloaded the email should be marked as Read.
Sub Downloademailattachementsfromexcellist()Dim olapp As Object Dim olmapi As Object Dim olmail As Object Dim olitem As Object Dim lrow As Integer Dim olattach As Object Dim str As String Const num As Integer = 6 Const path As String = "C:\HP\" ' i want this to fetch the value from excel worksheet something like ThisWorkbook.Sheets("Email Download").Range("C1").value Const olFolderInbox As Integer = 6 ' I want to define the common shared mailbox over here...instead of my own personal box. Common mailbox name is IGT Team Set olp = CreateObject("outlook.application") Set olmapi = olp.getnamespace("MAPI") Set olmail = olmapi.getdefaultfolder(num) If olmail.items.restrict("[UNREAD]=True").Count = 0 Then MsgBox ("No Unread mails") Else For Each olitem In olmail.items.restrict("[UNREAD]=True") lrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row + 1 Range("B" & lrow).Value = olitem.Subject ' each email subject line consists of date or some code which changes daily so I will just mention the unique part of the subject line which remains same daily. If olitem.attachments.Count <> 0 Then For Each olattach In olitem.attachments olattach.SaveAsFile path & olattach.Filename ' Once the attachement is downloaded I want the macro to mark the mail as Read Next olattach End If Next olitem End If End Sub





Reply With Quote
