PDA

View Full Version : Import data from excel file email attachment



olivetwist
07-09-2015, 12:03 PM
I have been tasked with figuring out a Rule to apply to the server. This rule needs to look at each email attachment. If the attachment is over a certain size I need to extract certain data from the file and import that data into a table in an access database.

I have code to look at attachments and if they are a certain size they get saved to a folder as a start.


Public Sub saveAttach(itm As Outlook.MailItem)
Dim sFileType As String
Dim fsSaveLoc As String: fsSaveLoc = "J:\Save\"
Dim objAtt As Outlook.Attachment
Dim strFile As String

For Each objAtt In itm.Attachments
strFile = objAtt.DisplayName
sFileType = LCase$(Right$(strFile, 4))
If (sFileType = ".xls" Or sFileType = "xlsx" Or sFileType = "xlsb" Or sFileType = "xlsm") _
And (objAtt.Size / 1024) > 43.1 Then
objAtt.SaveAsFile fsSaveLoc & strFile
End If
Next
End Sub

Any help is appreciated.