|
-
Feb 9th, 2018, 06:44 AM
#2
Re: download email attachments based on the subject line and folder names from a work
from the code it appears it should save all .xls attachments, but does not in anyway use the attachment file name in column A
depending on the number of emails in outlook folders there may be much better ways than looping all the folder items, you can use the items.restrict method, to limit the number of items to match the subject line
Code:
set sitems = subfolder.items.restrict("[subject]='" & subj & "'")
For Each Item In sitems
For Each Atmt In Item.Attachments
If LCase(Right(Atmt.FileName, Len(ExtString))) = LCase(ExtString) Then
FileName = DestFolder & Atmt.FileName
Atmt.SaveAsFile FileName
I = I + 1
End If
Next Atmt
Next Item
where subj is an additional parameter to the function, from the calling procedure
ActiveCell.Offset(1, 0).Select
there is no need for this line
also it would be better not to create an instance of outlook for every line in the worksheet, better to just have one instance and use the for all iterations
i believe i would just integrate the function in to the main procedure, though you could open an outlook instance in the main procedure, then pass the outlook subfolder to the function
Last edited by westconn1; Feb 9th, 2018 at 06:50 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|