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.
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?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
Thanks
Jeskit![]()
You can check for attachments like this I think:
Would need more info as to how you would deal with multiple attachments to be more specific.If OutMail.Attachments.Count > 0 Then ' Do whatever you want End If
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.
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
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
"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.
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
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.
"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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks