Solved

Excel VBA Looking for a match in Outlook header

Posted on 2011-03-11
2
231 Views
Last Modified: 2012-08-14
Hi

IIn the following Excel code: what additional code do I need to look for a match in the Outlook header
Private WithEvents appOL As Outlook.Application

Private Sub appOL_NewMailEx(ByVal EntryIDCollection As String)
   ' YOUR CODE GOES IN HERE
End Sub

Private Sub Workbook_Open()
   Set appOL = GetObject(, "Outlook.Application")
End Sub

Open in new window

0
Comment
Question by:murbro
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 35109672
Based on your earlier post:
Private Sub appOL_NewMailEx(ByVal EntryIDCollection As String)

On Error GoTo EH

   Dim arrEID As Variant, varEID As Variant, olkItem As Object
   arrEID = Split(EntryIDCollection, ",")
   Dim Atmt As Outlook.Attachment
   Dim FileName As String
   Dim MYDOC_DIR As String: MYDOC_DIR = Environ("userprofile") & "\Documents"
    
    For Each varEID In arrEID
        Set olkItem = appOL.Session.GetItemFromID(varEID)
        If olkItem.Class = olMail Then
            If InStr(olkItem.Subject, "Drilling Data") > 0 Then
                'Your code goes here'
                    For Each Atmt In olkItem.Attachments
                        FileName = MYDOC_DIR & "\Lesedi Drilling Data\" & Convert_Email(olkItem.SenderEmailAddress) & "_" & Atmt.FileName
                        Atmt.SaveAsFile FileName
                    Next Atmt
    
               oLoop
            End If
        If InStr(olkItem.Subject, "New Holes") > 0 Then
                'Your code goes here'
                    For Each Atmt In olkItem.Attachments
                        FileName = MYDOC_DIR & "\Lesedi Drilling Data\New Holes\" & Convert_Email(olkItem.SenderEmailAddress) & "_" & Atmt.FileName
                        Atmt.SaveAsFile FileName
                    Next Atmt
    
               oNewHole
            End If
        End If
    Next
    Set olkItem = Nothing
    Exit Sub
EH:
    MsgBox "There was an error processing an incoming email! " & Err.Description
End Sub

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 35109726
thanks very much for the help
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now