Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Outlook 2013, Save 2 Attachment’s to 2 separate locations and renaming one of them.

Hello here is my problem, I get an e-mail with two *.csv files attached in my inbox.
The first file is called for example custon2print this file needs to be save in a directory eg: (C:\vicpms\) this file never changes in name and can be save with the same name as received.

The second file example will have print1234.csv this file always changes with the last 4 or 5 digits example print1234 or print2345 etcetera, this file needs to be saved to desk-top but renamed as follows (print.csv)

Once this is done the VB project needs to the move that e-mail to a subfolder called (daily orders) then move onto any other e-mail that may be in the inbox with Attachment's but skipping past any attachment's that don't follow the above query!

I have played around with many ideas and so far have not be able to get this happing,

NEW TO visual basic FOR OUTLOOK................

Any help will be grateful.
-------------------------------------------------------------
Below is what I have come up with so far and works,

On Error GoTo GetAttachments_err

Dim ns As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim Atmt As Outlook.Attachment
Dim Item As Outlook.MailItem
Dim StringLength As Long
Dim Filename As String
Dim i As Integer

Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
i = 0
If Inbox.Items.Count = 0 Then
MsgBox "There are no messages in the Inbox.", vbInformation, _
"Nothing Found"
Exit Sub
End If

For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
If Left(Atmt.Filename, 12) Like "*custom2print*" Then
StringLength = Len(Atmt.Filename)
Filename = "C:\VICPMS\" & "custom2print.csv"
Atmt.SaveAsFile Filename
i = i + 1
End If
Next Atmt
Next Item
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
If Left(Atmt.Filename, 12) Like "*print1234*" Then
StringLength = Len(Atmt.Filename)
Filename = "C:\Users\whoever\Desktop\" & "print.csv"
Atmt.SaveAsFile Filename


i = i + 1
End If

Next Atmt

Next Item
Posted
Updated 17-Mar-15 21:47pm
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900