Hello i have macro where download all attachments from multiple emails, this code works fine, but I need change code to change every file name where was downloaded in folder, files name like "I10001258", "I10003256", "I10004758"... I wanna delete first five letters "I10001258", for all downloading files. Thanks!
Option Explicit
Sub Get_Attachments()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")
Dim msg As Outlook.MailItem
Dim fo As Outlook.Folder
Dim at As Outlook.Attachment
Set fo = Outlook.GetNamespace("MAPI").Folders("Your Mail Box Name Here").Folders("Inbox").Folders("My Report")
Dim lr As Integer
For Each msg In fo.Items
lr = Application.WorksheetFunction.CountA(sh.Range("A:A"))
sh.Range("A" & lr 1).Value = msg.Subject
sh.Range("B" & lr 1).Value = msg.Attachments.Count
For Each at In msg.Attachments
If VBA.InStr(at.Filename, ".xls") > 0 Then
at.SaveAsFile sh.Range("F1").Value & "\" & at.Filename
End If
Next
Next
MsgBox "Reports have been downloaded successfully"
End Sub
CodePudding user response:
Mid()
can be used to skip the first characters.
at.SaveAsFile sh.Range("F1").Value & "\" & Mid(at.Filename, 6)