![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
Hi,
I need to dump emails in a specific folder into a text file. I get about 10-20 of these emails per day. I will then use VBA code to handle the text file and import the data into excel. I just don't know how to handle the messages in outlook. How would I write this code? Thanks, |
#2
|
|||
|
|||
![]()
The most important first step is to state what your goal is, because
there appear to be multiple ways to do what you want. Saying you want to dump emails into a text file is limiting your goal to just one particular solution. There are also some details missing. You want to place the text of the email into Excel, just the Body? What about the headers? Do they all need to be in one row or column? There's a tip here that might get you started. http://www.exceltip.com/st/Log_files...Excel/467.html It would be simple to loop through a folder in Outlook, assign the Body of each email to a string, and then write the string to a text file using the macro code in that link. HTH, JP On Sep 11, 2:57*pm, Rob wrote: Hi, I need to dump emails in a specific folder into a text file. I get about 10-20 of these emails per day. * I will then use VBA code to handle the text file and import the data into excel. *I just don't know how to handle the messages in outlook. *How would I write this code? Thanks, |
#3
|
|||
|
|||
![]() "JP" wrote: The most important first step is to state what your goal is, because there appear to be multiple ways to do what you want. Saying you want to dump emails into a text file is limiting your goal to just one particular solution. There are also some details missing. You want to place the text of the email into Excel, just the Body? What about the headers? Do they all need to be in one row or column? There's a tip here that might get you started. http://www.exceltip.com/st/Log_files...Excel/467.html It would be simple to loop through a folder in Outlook, assign the Body of each email to a string, and then write the string to a text file using the macro code in that link. HTH, JP On Sep 11, 2:57 pm, Rob wrote: Hi, I need to dump emails in a specific folder into a text file. I get about 10-20 of these emails per day. I will then use VBA code to handle the text file and import the data into excel. I just don't know how to handle the messages in outlook. How would I write this code? Thanks, Thank you for your reply JP. My end goal is to automate the task of transporting the contents of these emails into an Excel table. I want to do it programmatically. Each Email contains 7 rows with a row in between. It looks like the following... Overall service rating: 10 Assisting Agent Name: Josh Additional Comments: Great customer service Customer Name: Customer Email Address: Customer Phone #: Customer Account #: In the meantime, I will read this page you suggested and see if I can figure it out myself... |
#4
|
|||
|
|||
![]()
If you know for sure that the contents of each email are in that same
exact format, it's a simple matter to parse each email body and look for the text you want. Here's some VBA in Outlook that sets a reference to each email in your default Inbox and writes some properties to an Excel worksheet. It's untested but it should work to show you how you can write to a worksheet from Outlook. (Based on http://www.codeforexcelandoutlook.co...acts-to-excel/) Option Explicit Sub ExtractEmailsFromOutlookToExcel() Dim olApp As Outlook.Application Dim olNS As Outlook.NameSpace Dim myItems As Outlook.Items Dim ThisItem As Object Dim Msg As Outlook.MailItem Dim xlApp As Excel.Application Dim MyBook As Excel.Workbook Dim MySheet As Excel.Worksheet Dim arrData() As Variant Dim i As Long Application.ScreenUpdating = False Set olApp = Outlook.Application Set olNS = olApp.GetNamespace("MAPI") Set myItems = olNS.GetDefaultFolder(olFolderInbox).Items If myItems.Count 0 Then ' resize data array to hold 3 random msg properties ReDim arrData(1 To myItems.Count, 1 To 3) ' get Excel and set up some basic wksht properties Set xlApp = GetExcelApplication Set MyBook = xlApp.Workbooks.Add Set MySheet = MyBook.Sheets(1) MySheet.Name = "Emails" ' loop through each item and write to array For i = 1 To myItems.Count If TypeName(myItems.Item(i)) = "MailItem" Then Set Msg = ThisItem With Msg arrData(i, 1) = .Sensitivity arrData(i, 2) = .ReceivedTime arrData(i, 3) = .SenderEmailType End With End If Next i ' dump array to worksheet in one shot MySheet.Range("A1").Offset(1, 0).Resize(myItems.Count, 3).Value = arrData End If ExitProc: Set olApp = Nothing Set olNS = Nothing Set myItems = Nothing End Sub Function GetExcelApplication() On Error Resume Next Set GetExcelApplication = GetObject(, "Excel.Application") If Err 0 Then Set GetExcelApplication = CreateObject("Excel.Application") End If On Error GoTo 0 End Function On Sep 12, 2:32*pm, Rob wrote: "JP" wrote: The most important first step is to state what your goal is, because there appear to be multiple ways to do what you want. Saying you want to dump emails into a text file is limiting your goal to just one particular solution. There are also some details missing. You want to place the text of the email into Excel, just the Body? What about the headers? Do they all need to be in one row or column? There's a tip here that might get you started. http://www.exceltip.com/st/Log_files...soft_Excel/467... It would be simple to loop through a folder in Outlook, assign the Body of each email to a string, and then write the string to a text file using the macro code in that link. HTH, JP On Sep 11, 2:57 pm, Rob wrote: Hi, I need to dump emails in a specific folder into a text file. I get about 10-20 of these emails per day. * I will then use VBA code to handle the text file and import the data into excel. *I just don't know how to handle the messages in outlook. *How would I write this code? Thanks, Thank you for your reply JP. *My end goal is to automate the task of transporting the contents of these emails into an Excel table. *I want to do it programmatically. * Each Email contains 7 rows with a row in between. *It looks like the following... Overall service rating: 10 Assisting Agent Name: Josh Additional Comments: Great customer service * * *Customer Name: Customer Email Address: * Customer Phone #: Customer Account #: In the meantime, I will read this page you suggested and see if I can figure it out myself |
#5
|
|||
|
|||
![]()
Hi, there!
I have a similar problem, where I have an email message sent by our webform, which body content has to be parsed into an Excel file. I'm not familar with VBA, so I've copied and pasted the code below into my Outlook VBA and tried to run, but first of all, it gives me an error message at line "arrData(i, 1) = .Sensitivity". Would anybody have any clue about why it is happening? Also, I have lots of e-mails in my Inbox, but I just need the ones with certain words in their Subject. How would I define these words? Thank you! |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
dumping deleted items in Outlook | JD | Outlook - Using Contacts | 1 | April 29th 08 09:17 PM |
Users local emails not in sync with Exchange 2007.. so i deleted their ost file (resetting cached mode).. Typical ? | markm75 | Outlook - General Queries | 0 | October 12th 07 01:20 AM |
how to select a different users calendar when using VB script to create calendar dumping tool ? | mike[_3_] | Outlook and VBA | 1 | October 8th 07 06:13 PM |
dumping calendar and other outlook info over to ACCESS | Babs | Outlook - Calandaring | 3 | June 15th 07 10:31 PM |
Auto dumping of delected mail | Spectrumone | Outlook - General Queries | 2 | February 14th 07 10:48 PM |