Murray Brown
asked on
Excel VBA - process incoming Outlook emails
Hi
I was given the following code to process incoming emails from within Excel
but am not sure where to put it. I put it in the ThisWorkbook module and it didn't activate
I was given the following code to process incoming emails from within Excel
but am not sure where to put it. I put it in the ThisWorkbook module and it didn't activate
Private Sub appOL_NewMailEx(ByVal EntryIDCollection As String)
'YOUR CODE GOES IN HERE
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, "SMS Message received") > 0 Then
'Your code goes here'
'For Each Atmt In olkItem.Attachments
'FileName = MYDOC_DIR & Atmt.FileName
'Atmt.SaveAsFile FileName
'Next Atmt
MsgBox "Received"
End If
End If
Next
Set olkItem = Nothing
Exit Sub
EH:
MsgBox "There was an error processing an incoming email! " & Err.Description
End Sub
Beg pardon ... it looked like outlook code but I see now the name appOL_NewMailEx so perhaps it's not but I suggest it is called by thisoutlooksession.
ASKER
Hi Chris, I though this would work in Excel?
ASKER
Hi Chris. Sent reply before reading your second reply. So where exactly would I put that? In an Outlook event?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks very much
Chris