Save outlook attachments and rename/append files with identifier from subject line

Status
Not open for further replies.

CalGal80

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server 2010
Im really new to VBA and need some help. I'm trying to write a VBA script (along with a Outlook rule) to automatically download attachments from daily emails that contain multiple attachements and append the file names with the date that always appears at the end of the subject line.

This is what the subject line looks like - "Email Alert for Department for 10/20/2014". I just need to isolate the rightmost 10 spaces that indicates the run date of the files.

So I found code online that works to automatically download the attachments and append by current date which does work. See below.

Code:
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
dateFormat = Format(Now, "yyyymmdd ")
saveFolder = "Z:\Daily Emails"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub

I tried to modify the code to append the file name by using the last 10 spaces of the subject line instead of the current date but when I ran the rule with the script it did not work.

Code:
Public Sub saveAttachtoDiskCL(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim savefolder As String
Dim Subject As String
savefolder = "Z:\Daily Emails"
     For Each objAtt In itm.Attachments
Subject = itm.Subject

'Isolate last 10 spaces
Subject = Right(itm.Subject, 10)
objAtt.SaveAsFile savefolder & "\" & objAtt.DisplayName & Subject
Set objAtt = Nothing
Next
End Sub

I feel like its something small I'm overlooking. Any thoughts?
 
Thanks for the tip but I just fixed it and it still doesnt work. What I did notice was that the progress bar moved faster but still nothing being saved into my folder.

Im running the rule with the script on emails that have already been received so Im looking to auto download all attachments from historical emails. Do you think that is making a difference?

Anyone else with ideas?

here is the modified code.

Code:
Public Sub saveAttachtoDiskCL(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim savefolder As String
Dim Subject As String
savefolder = "Z:\Daily Emails"
     For Each objAtt In itm.Attachments
Subject = itm.Subject

'Isolate last 10 spaces
Subject = Right(itm.Subject, 10)
objAtt.SaveAsFile savefolder & "\" & Subject & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
 
Set a breakpoint into the code so the execution stops there, then go through it step by step with f8. Especially see if savefolder & "\" & Subject & objAtt.DisplayName is a valid file name. Also, the folder in savefolder must exist already.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
G Save and Rename Outlook Email Attachments Outlook VBA and Custom Forms 0
W Save and rename outlook email attachments to include domain name & date received Outlook VBA and Custom Forms 4
C Auto save outlook attachments when email is received Outlook VBA and Custom Forms 1
Diane Poremsky Edit and Save Outlook's Read-Only Attachments Using Outlook 0
S using script rule to save attachments on arrival Outlook 2010 Outlook VBA and Custom Forms 9
R Outlook 2013 VB rule to auto save attachments with different file types Outlook VBA and Custom Forms 5
E Outlook prompts to save attachments when no changes have been made. Using Outlook 0
A File - Save Attachments does nothing in Outlook 2003 with Exchange 2010 ... Using Outlook 3
O closing outlook prompts to save all opened attachments Using Outlook 2
M Outlook 2007 - Save outgoing attachments to network drive on sending? Using Outlook 1
G Save emails as msg file from Outlook Web AddIn (Office JS) Outlook VBA and Custom Forms 0
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
C Outlook (desktop app for Microsoft365) restarts every time I save my VBA? Using Outlook 1
G VBA to save selected Outlook msg with new name in selected network Windows folder Outlook VBA and Custom Forms 1
D Outlook 2016 64bit, Cannot Save in 'HTML', format Using Outlook 1
S Outlook (2016 32bit; Gmail IMAP) - Save sent message to Outllook Folder Outlook VBA and Custom Forms 0
P Outlook pst file is too huge with POP3. How to save more space? Using Outlook 4
W Outlook Calendar does not save view any longer! Using Outlook 3
9 Outlook 2016 How to save an Outlook attachment to a specific folder then delete the email it came from? Using Outlook 1
W Save Outlook attachment in network folder and rename to current date and time Outlook VBA and Custom Forms 18
C Outlook - cannot save subject line changes Using Outlook 2
I Outlook 2016 64bit - on receipt convert emails into PDF and save Outlook VBA and Custom Forms 2
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
Diane Poremsky Export (Save) Outlook Contact photos Using Outlook 0
E Outlook 2016 and Numerous Prompts to Save Emails Using Outlook 3
Diane Poremsky Save Outlook Email as a PDF Using Outlook 0
L Save message from outlook to desktop in 2013 outlook Outlook VBA and Custom Forms 1
Mark Foley Where are Outlook categories save for IMAP? Using Outlook 12
J Auto-Save for Outlook Calendar Entries Using Outlook 5
L Outlook 2007 Macro Save Contact Using Outlook 10
B Outlook 2007 Save Current View,Font,Toolbar Settings Using Outlook 6
F Outlook 2010 custom font style duplicates itself every time I save a task Using Outlook 0
C How To Open Outlook Attachment in Excel, Modify some Data, then Re-Save It Using Outlook 3
B Outlook 2010 won't save 'current view' with reading pane at 'bottom' Using Outlook 4
O Export (save) Outlook Contact photos Using Outlook 2
E can't save draft email in Outlook 2010 Using Outlook 2
F CAN'T SAVE OUTLOOK 2010 E-MAIL TEMPLATE (.oft) Using Outlook 1
S Save Attachement from outlook Using Outlook 2
Rupert Dragwater Can't save font type in Outlook 2010 Using Outlook 3
S Outlook 2010: Cannot save forms templates to folder list Using Outlook 4
D outlook to save copy of hotmail? Using Outlook 3
E Strange save request when closing Outlook 2007 Outlook VBA and Custom Forms 4
E Strange save request when closing Outlook 2007 Outlook VBA and Custom Forms 4
H Where does Outlook 2007 save the default reminder settings? Outlook VBA and Custom Forms 1
S save attachment using outlook 2007 Outlook VBA and Custom Forms 1
M Save as Adobe PDF misses inline graphics Using Outlook 0
Sandgroper48 Save vbaProject Outlook VBA and Custom Forms 2
J Outlook 2019 Pick the Folder Location to save send emails Outlook VBA and Custom Forms 0
boblewis Technical Issue with Custom Form - Save to Drafts Not Syncing Outlook VBA and Custom Forms 1

Similar threads

Back
Top