Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Extracting Data from MS Outlook Mail Messages

Hi all,
I have a problem.

I am recieving a number of email messages from which I need to extract the
contents of the mail message body and import it into Excel. The data comes
from HTML forms that are Emailed to me.

The body of the Mail Message contains data in the following format:

jobno=100325
contract=RS-330
jobtype=Asphalt
completedate=20/03/2003

What I want to do is extract the data from the mail message and insert it in
to Excel.
The bit before the = should be the column name
Anyone know where I should start.

TIA
Steve


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Extracting Data from MS Outlook Mail Messages

Hi Steve,

Do the emails all have the same subject lines / come from the same
sender?

Does the body contain only the format you specified and nothing more?



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Extracting Data from MS Outlook Mail Messages


Following would work for PLAINTEXT messages. For HTML you'd need to
strip any tags found..

note the routine to loop/select messages from the inbox is rudimentary
and for illustration only.

You MUST set a reference to the Outlook Object Library.
Hope it gets you on your way :)



Option Explicit
Option Compare Text

Sub ReadInbox()
Dim appOL As Outlook.Application
Dim oSpace As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
Dim oItems As Outlook.Items
Dim oMail As Outlook.MailItem

Set appOL = CreateObject("Outlook.Application")
Set oSpace = appOL.GetNamespace("MAPI")
Set oFolder = oSpace.GetDefaultFolder(olFolderInbox)
Set oItems = oFolder.Items
oItems.Sort "Received", True
For Each oMail In oItems
If oMail.Subject Like "*BodyTest*" Then
Call bodyStrip(oMail)
End If
Next
End Sub

Sub bodyStrip(msg As Outlook.MailItem)
Dim sBody As String
Dim aFields As Variant
Dim r As Range
Dim n&, iPos1&, ipos2&

aFields = Array("jobno=", "contract=", "jobtype=", "completedate=")

Set r = [a65536].End(xlUp).Offset(1).Resize(, 4)
sBody = msg.Body

For n = 1 To 4
iPos1 = InStr(ipos2 + 1, sBody, aFields(n - 1))
If iPos1 0 Then
iPos1 = iPos1 + Len(aFields(n - 1))
ipos2 = InStr(iPos1 + 1, sBody, vbCrLf)
r(n) = Mid(sBody, iPos1, ipos2 - iPos1)
Else
Exit For
End If
Next
End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Steve Wright" wrote:

Hi all,
I have a problem.

I am recieving a number of email messages from which I need to extract
the contents of the mail message body and import it into Excel. The
data comes from HTML forms that are Emailed to me.

The body of the Mail Message contains data in the following format:

jobno=100325
contract=RS-330
jobtype=Asphalt
completedate=20/03/2003

What I want to do is extract the data from the mail message and insert
it in to Excel.
The bit before the = should be the column name
Anyone know where I should start.

TIA
Steve



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Extracting Data from MS Outlook Mail Messages

Yes the subject lines are all the same but the message may come from four or
five different people.

The body contains only the specified format


Steve
"zantor" wrote in message
...
Hi Steve,

Do the emails all have the same subject lines / come from the same
sender?

Does the body contain only the format you specified and nothing more?



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Extracting Data from MS Outlook Mail Messages

Works great thanks!!

Next question!

This works with the Inbox. I would like to make it work with a folder
called "RAMM" as I have a rule in outlook that transfers those messages
there.

Also I would like to "move" the message to another mailbox that I have
access to.

Any help appreciated

Steve


"keepitcool" wrote in message
...

Following would work for PLAINTEXT messages. For HTML you'd need to
strip any tags found..

note the routine to loop/select messages from the inbox is rudimentary
and for illustration only.

You MUST set a reference to the Outlook Object Library.
Hope it gets you on your way :)



Option Explicit
Option Compare Text

Sub ReadInbox()
Dim appOL As Outlook.Application
Dim oSpace As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
Dim oItems As Outlook.Items
Dim oMail As Outlook.MailItem

Set appOL = CreateObject("Outlook.Application")
Set oSpace = appOL.GetNamespace("MAPI")
Set oFolder = oSpace.GetDefaultFolder(olFolderInbox)
Set oItems = oFolder.Items
oItems.Sort "Received", True
For Each oMail In oItems
If oMail.Subject Like "*BodyTest*" Then
Call bodyStrip(oMail)
End If
Next
End Sub

Sub bodyStrip(msg As Outlook.MailItem)
Dim sBody As String
Dim aFields As Variant
Dim r As Range
Dim n&, iPos1&, ipos2&

aFields = Array("jobno=", "contract=", "jobtype=", "completedate=")

Set r = [a65536].End(xlUp).Offset(1).Resize(, 4)
sBody = msg.Body

For n = 1 To 4
iPos1 = InStr(ipos2 + 1, sBody, aFields(n - 1))
If iPos1 0 Then
iPos1 = iPos1 + Len(aFields(n - 1))
ipos2 = InStr(iPos1 + 1, sBody, vbCrLf)
r(n) = Mid(sBody, iPos1, ipos2 - iPos1)
Else
Exit For
End If
Next
End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Steve Wright" wrote:

Hi all,
I have a problem.

I am recieving a number of email messages from which I need to extract
the contents of the mail message body and import it into Excel. The
data comes from HTML forms that are Emailed to me.

The body of the Mail Message contains data in the following format:

jobno=100325
contract=RS-330
jobtype=Asphalt
completedate=20/03/2003

What I want to do is extract the data from the mail message and insert
it in to Excel.
The bit before the = should be the column name
Anyone know where I should start.

TIA
Steve







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Extracting Data from MS Outlook Mail Messages

sorry for slow response


read www.rondebruin.nl for plenty of info on working with outlook.



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Steve Wright" wrote:

Works great thanks!!

Next question!

This works with the Inbox. I would like to make it work with a folder
called "RAMM" as I have a rule in outlook that transfers those messages
there.

Also I would like to "move" the message to another mailbox that I have
access to.

Any help appreciated

Steve


"keepitcool" wrote in message
...

Following would work for PLAINTEXT messages. For HTML you'd need to
strip any tags found..

note the routine to loop/select messages from the inbox is rudimentary
and for illustration only.

You MUST set a reference to the Outlook Object Library.
Hope it gets you on your way :)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing saved e-mail messages Positive Outlooker Setting up and Configuration of Excel 1 February 24th 09 11:23 PM
Extracting data from Outlook to Excel using VBA HBruno Excel Worksheet Functions 0 July 23rd 08 03:32 PM
Combining data from Excel with Outlook address book to mail bills Joe Porkka [MSFT] Excel Discussion (Misc queries) 3 August 26th 07 05:12 AM
E-Mail attachment to same e-mail address in Outlook Vick Excel Discussion (Misc queries) 4 May 17th 07 07:53 PM
hyperink outlook mail messages to cells in excell bembel Excel Discussion (Misc queries) 0 October 20th 05 06:56 PM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"