Extracting data from email attachments?

zakynthos

Board Regular
Joined
Mar 28, 2011
Messages
169
I’m looking for a process to:


  • · Extract key fields from Outlook (2007) xlsx attachments
  • · Log key fields from the attachments
(Export them to one row of an Excel spreadsheet for archiving
(attaching a unique identifier (UI) to the analyst processing it (example 13JUL11-0900-001, where the first part consists of date/month (current date)/current time and the last 3 integers are sequential integers from 1-200.)

  • · Email the original attachment to a team member (appending the unique identifier as above)
Example:
At 090:00, say the Team inbox has 200 emails (max no.) and they are to be divided between 10 team members, i.e 20 each.
The date and time that the information is processed is 13 July 2011 at 09:03
For team member 1 (whose initials are ME) the unique identifier would be:
“ME-13JUL-0903-001”
Team member 1 would then be allocated the next 19 emails in date/time order, with unique identifiers:
“ME-13JUL-0903-002” to “ME-13JUL-0903-020”


The tab of the xlsx attachments containing the key fields is called:

“Agency – single”


The 8 items of info to be extracted from the attachment are as follows:


EIN, OUC, Surname, Firstname, Requestor, Requestor UIN, Start date, End date


I have VBA (below) which I’ve tested for sending out xlsx files from Excel to a distribution list, but it’s not really what I need for the above process - but I wonder whether it could be modified to include the search and other criteria above to produce a workable system.




Two other constraints:


1. 1. I don’t have administrative access to the network – so won’t be able to use VBA from within Outlook 2007, as I cannot make any registry changes or select Microsoft Outlook library options etc.


2. 2. The search/distribution process will need to be repeated within a day so I would need code to clear each of the 200 emails from team inbox once forwarded and archive to another mail folder.



Code:
Sub Mail_ActiveSheet()   
'Working in 97-2010
       Dim FileExtStr As String
       Dim FileFormatNum As Long
       Dim Sourcewb As Workbook
       Dim Destwb As Workbook
       Dim TempFilePath As String
       Dim TempFileName As String
       Dim I As Long
       With Application
           .ScreenUpdating = False
           .EnableEvents = False
       End With
       Set Sourcewb = ActiveWorkbook
       'Copy the sheet to a new workbook
       ActiveSheet.Copy
       Set Destwb = ActiveWorkbook
       'Determine the Excel version and file extension/format
       With Destwb
           If Val(Application.Version) < 12 Then
               'You use Excel 97-2003
               FileExtStr = ".xls": FileFormatNum = -4143
           Else
               'You use Excel 2007-2010, we exit the sub when your answer is
               'NO in the security dialog that you only see  when you copy
               'an sheet from a xlsm file with macro's disabled.
               If Sourcewb.Name = .Name Then
                   With Application
                       .ScreenUpdating = True
                       .EnableEvents = True
                   End With
                   MsgBox "Your answer is NO in the security dialog"
                   Exit Sub
               Else
                   Select Case Sourcewb.FileFormat
                   Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                   Case 52:
                       If .HasVBProject Then
                           FileExtStr = ".xlsm": FileFormatNum = 52
                       Else
                           FileExtStr = ".xlsx": FileFormatNum = 51
                       End If
                   Case 56: FileExtStr = ".xls": FileFormatNum = 56
                   Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                   End Select
               End If
           End If
       End With
       '    'Change all cells in the worksheet to values if you want
       '    With Destwb.Sheets(1).UsedRange
       '        .Cells.Copy
       '        .Cells.PasteSpecial xlPasteValues
       '        .Cells(1).Select
       '    End With
       '    Application.CutCopyMode = False
       'Save the new workbook/Mail it/Delete it
       TempFilePath = Environ$("temp") & "\"
       TempFileName = "Part of " & Sourcewb.Name & " " _
                    & Format(Now, "dd-mmm-yy h-mm-ss")
       With Destwb
           .SaveAs TempFilePath & TempFileName & FileExtStr, _
                   FileFormat:=FileFormatNum
           On Error Resume Next
           For I = 1 To 13
               .SendMail "am@abc.com", _
                         "Your work for 20/07/11 1"
                         .SendMail "am@abc.com", _
                         "Your work for 20/07/11 2"
                         .SendMail "am@abc.com", _
                         "Your work for 20/07/11 3"
                         .SendMail "am@abc.com", _
                         "Your work for 20/07/11 4"
                         .SendMail "am@abc.com", _
                         "Your work for 20/07/11 5"
                       .SendMail "pm@xyz.com", _
                         "Your work for 20/07/11 1"
                         .SendMail "am@abc.com", _
                         "Your work for 20/07/11 2"
                         .SendMail "pm@xyz.com", _
                         "Your work for 20/07/11 3"
                         .SendMail "pm@xyz.com", _
                         "Your work for 20/07/11 4"
                         .SendMail "pm@xyz.com", _
                         "Your work for 20/07/11 5"
           If Err.Number = 0 Then Exit For
           Next I
           On Error GoTo 0
           .Close SaveChanges:=False
       End With
       'Delete the file you have send
       Kill TempFilePath & TempFileName & FileExtStr
       With Application
           .ScreenUpdating = True
           .EnableEvents = True
       End With
   End Sub
Many thanks!:)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top