Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel VBA Looking for a match in Outlook header

Posted on 2011-03-11
2
Medium Priority
?
246 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 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:Murray Brown
ID: 35109726
thanks very much for the help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

705 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