+ Reply to Thread
Results 1 to 6 of 6

Outlook 2010 macro to extract data from email

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Outlook 2010 macro to extract data from email

    Hi

    I have written this macro in Microsoft Outlook 2010 which opens an excel workbook and then from the open email extracts data from the email and inserts it into the excel workbook.

    Option Explicit
    Sub EmailExtracter()
    
    Dim strFldr As String
    Dim OEM, Nrow As String
    Dim SuggestOEM As Integer
    Dim OutMail As Object
    Dim xlApp, xlbook, xlbookSht As Object
    
    Set OutMail = ActiveInspector.CurrentItem
    
    strFldr = "C:\Documents and Settings\SeymourJ\Desktop\Tasks"
    
    Set xlApp = CreateObject("Excel.Application")
        xlApp.Application.Visible = True
        xlApp.Workbooks.Open strFldr & "\EmailTest.xls"
    Set xlbook = xlApp.Workbooks.Open(strFldr & "\EmailTest.xls")
    Set xlbookSht = xlbook.sheets("EmailData")
    
    Nrow = xlApp.WorksheetFunction.CountA(xlbookSht.Range("A:A"))
    OEM = xlApp.Application.InputBox("Please enter the OEM name of the email", "OEM Entry Box", SuggestOEM)
    
    If OEM = "" Or OEM = 0 Then
        MsgBox "Please enter a name or enter Not Applicable, Thank you"
        OEM = xlApp.Application.InputBox("Please enter the OEM name of the email", "OEM Entry Box", SuggestOEM)
    End If
    
    Nrow = xlApp.WorksheetFunction.CountA(xlbook.sheets("EmailData").Range("A:A"))
    
    xlbookSht.Range("A" & Nrow + 1).Value = OEM
    
    xlbookSht.Range("B" & Nrow + 1).Value = OutMail.SenderEmailAddress
    
    xlbookSht.Range("C" & Nrow + 1).Value = OutMail.To
    
    xlbookSht.Range("D" & Nrow + 1).Value = OutMail.CC
    
    xlbookSht.Range("E" & Nrow + 1).Value = OutMail.SentOn
    
    xlbookSht.Range("F" & Nrow + 1).Value = OutMail.ReceivedTime
    
    xlbookSht.Range("G" & Nrow + 1).Value = OutMail.Subject
    
    xlbookSht.Columns("A:H").EntireColumn.AutoFit
    
    xlbookSht.SaveAs strFldr & "\" & "EmailTest.xls"
    
    End Sub
    However does anyone know how to add a line which says if there is an attachment place the name of the file into column H else put False into column H?

    Thanks

    Jeskit

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Outlook 2010 macro to extract data from email

    You can check for attachments like this I think:

    If OutMail.Attachments.Count > 0 Then
    ' Do whatever you want
    End If
    Would need more info as to how you would deal with multiple attachments to be more specific.

    Dom
    Last edited by Domski; 06-13-2011 at 05:51 AM.
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Valued Forum Contributor
    Join Date
    01-10-2011
    Location
    swindon, england
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Outlook 2010 macro to extract data from email

    Hi

    Thanks for that, that works!

    Would you know that the item class is for attaching the name of the attachment?? I ahve tried .Attachments, .AttachmentsAdd but they didn't work.

    Thanks

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Outlook 2010 macro to extract data from email

    Something like this:

    Dim itm As Object
    Dim OutMail As MailItem
    
    Set itm = ActiveInspector.CurrentItem
    
    If itm.Class = olMail Then
        Set OutMail = itm
        If OutMail.Attachments.Count > 0 Then
            MsgBox OutMail.Attachments(1).Filename
        End If
    End If

    Dom

  5. #5
    Forum Contributor
    Join Date
    06-04-2011
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    108

    If a Table is in the body of a mail.. want to extract the same in to the excel cells

    Hi,.

    Can anyone help me in getting out of this..

    In outlook emails, if in the body of a mail contains like any tables.. how to get that table of contents from the body of a mail to excel cell by cell using macro programming..

    Please help me with the code.....

    urgently needed.....



    Thanks & Regards
    Chaitanya Balaji

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: If a Table is in the body of a mail.. want to extract the same in to the excel ce

    You should start your own thread rather than posting a question in another persons per the forum rules.

    Dom
    Last edited by Domski; 06-27-2011 at 05:48 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1