Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic process to Extract body text from outlook

Status
Not open for further replies.

malpa

Technical User
Feb 8, 2004
122
CO
Hi

I want to read , extract and save body text messagges from outlook each time that I recive them. I want to save this messagges in csv logs.

My initial programm, it has an error.

Public Sub ReadEmails()
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim SolFolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem
Dim lngRow As Long
Dim Sbody


Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set olFolder = olNamespace.Folders("Carpetas personales")
Set SolFolder = olFolder.Folders("linea922010")

lngRow = 1
For Each olMail In SolFolder.Items
With ActiveSheet
.Cells(lngRow, 1) = olMail.SenderName ####error object ?????
.Cells(lngRow, 2) = olMail.Subject
.Cells(lngRow, 3) = olMail.Body
lngRow = lngRow + 1
' Sbody = olMail.Body
' MsgBox Sbody
End With
Next

Set olMail = Nothing
Set olFolder = Nothing
Set SolFolder = Nothing
Set olNamespace = Nothing
Set olApp = Nothing
End Sub

Any suggestions

Thanks
Malpa
 
I'd try something like this:
Code:
...
    For Each olMail In SolFolder.Items
      [!]If olMail.Class = olMail Then[/!]
        With ActiveSheet
            .Cells(lngRow, 1) = olMail.SenderName
            .Cells(lngRow, 2) = olMail.Subject
            .Cells(lngRow, 3) = olMail.Body
            lngRow = lngRow + 1
        End With
      [!]End If[/!]
    Next
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PVH
Thanks for your input.
Im triyng to work in VBA, but I dont know nothing about it.

I was working on the solution and I found that a way to automate the receipt of mails, was working on thisOutlookSession module, by means of rules.
Each time that I recive a mail with a especific subject, I want to extract body text form incomming mesagges, then save it on a workbook.

this is a new programm

Sub ReadEmails(MyMail As MailItem)-> this line is Mandatory

Dim strID As String
Dim objMail As Outlook.MailItem
Dim lngRow As Long
strID = MyMail.EntryID

Set objMail = Application.Session.GetItemFromID(strID)
objMail.BodyFormat = olFormatPlain
objMail.Save

'lngRow = 1
'With ActiveSheet
' .Cells(lngRow, 1) = objMail.Subject
' .Cells(lngRow, 2) = objMail.SenderName
' .Cells(lngRow, 3) = objMail.Body
' lngRow = lngRow + 1
' End With


Open "C:\TestO.txt" For Output As #1
Print #1, objMail.Body
Close #1

Set objMail = Nothing
End Sub


The issue is the next: I dont undesrtand why reason the program can not to write on the activsheet, but if i save the body into to the file.txt, that funtion fine.


Thanks
Malpa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top