+ Reply to Thread
Results 1 to 2 of 2

VBA to identify a specific email and copy the attachment from it to the network

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    Excel 2021
    Posts
    1,013

    VBA to identify a specific email and copy the attachment from it to the network

    Hi,

    I've created a scheduler in our Cognos reporting system that emails me an updated data extract each morning. What I would like is a macro that identifies this daily email (perhaps when I open outlook?) and copies the attachment to a defined area on the network. If it helps the email address, subject name and attachment name are always the same. For the purposes of this let's say they are as follows:

    Email - Snook@hotmail.com
    Subject - Cognos Data Extract
    Attachment - Data Extract.xlsx
    Network Address - \\network\performance management

    What would also be useful is if the email could be moved to another folder within my inbox once the attachment has been extracted, e.g. named 'Cognos'.

    If you require any further info just give me a shout.

    Thanks in advance,

    Snook
    Last edited by The_Snook; 09-10-2014 at 03:54 AM.

  2. #2
    Forum Contributor Gregor y's Avatar
    Join Date
    10-24-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2010 32-Bit
    Posts
    280

    Re: VBA to identify a specific email and copy the attachment from it to the network

    I sugest that you create a rule to move the emails into the 'Cognos' folder then set a ribbon button for the following macro that you can run while viewing the 'Cognos' folder. That way you wouldn't need to update the code if your email selection criteria changes you'd just update the outlook rule.

    Public Sub ExportAttachments()
        'I'm not sure if a UNC path will work you may need to map a network drive
        Const pth As String = "\\network\performance management\"
        Dim fldr As MAPIFolder, itm As Object, em As MailItem, a As Attachment
        'I just took a guess with 'Mailbox - Snook', it'll be whatever the name of the "Data File" is
        '   it should be the root folder for your Inbox
        'Set fldr = Application.GetNamespace("MAPI").Folders("Mailbox - Snook").Folders("Cognos")
        'For Each itm In fldr.Items
        For Each itm In ActiveExplorer.CurrentFolder
        If itm.Class = olMail Then
            Set em = itm
        If em.Importance <> olImportanceLow Then
            For Each a In em.Attachments
                a.SaveAsFile pth & Format(em.SentOn, "yymmddhhmm") & " " & a.FileName
            Next a
            em.Importance = olImportanceLow
            em.Save
        End If: End If
        Next itm
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Automatically Copy Data in Excel File upon opening email attachment
    By rachaelgoldman1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2013, 05:21 AM
  2. Macro to prevent sending email (attachment) unless specific cells are populated
    By StartRunMSPaint in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-19-2013, 01:51 PM
  3. Copy selected range from email attachment and paste into closed workbook
    By Lisa4legin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-15-2013, 09:32 AM
  4. Email a copy of a sheet to a specific person using an email on the worksheet. - VBA
    By j_lad_1999 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-03-2009, 11:38 AM
  5. automatic attachment to specific email
    By elsiegee1 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 12-05-2006, 04:28 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1