Consulting

Results 1 to 2 of 2

Thread: Outlook 2013, Save 2 Attachment’s to 2 separate locations and renaming one of them

  1. #1

    Outlook 2013, Save 2 Attachment’s to 2 separate locations and renaming one of them

    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.csv 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.

  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •