PDA

View Full Version : Importing multiple lines of text from outlook via vba



Ecam
08-10-2008, 11:59 PM
Hello,

Is there a way to read the entire email body in Outlook via VBA code Outlook.Items? I am implementing an application in Access via VBA to read the entire email body which could contains several lines of text.

I tried the Outlook.Items.Body and it only returns the first line of the email body?

Please is there a way to read the entire body (all lines)?

Thanks,

Mavyak
08-11-2008, 07:01 AM
The Body property should be returning all lines. Perhaps you're viewing the contents in debug mode by hovering over the variable? Doing so will not show line feeds or carriage returns. Also, sometimes an email looks multi-line when it is really just too long for the window you are viewing it in so it wraps the text. Can you post your code?

Ecam
08-11-2008, 09:38 AM
Thanks Mavyak for quick response. Below is the code that I am using. Please note that I importing the data to an access table with the body field set to MEMO and still get the first line of the body!

Public Sub Inbox_Reader()
Dim TempRst As DAO.Recordset
Dim rst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim MyInbox As Outlook.MAPIFolder
Dim MyInboxItems As Outlook.Items
Dim Mailobject As Object
Dim db As DAO.Database
Dim dealer As Integer
DoCmd.RunSQL "Delete * from Email_tbl"
Set db = CurrentDb
Set OlApp = CreateObject("Outlook.Application")
Set MyInbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderMyInbox)
Set TempRst = CurrentDb.OpenRecordset("tbl_OutlookTemp")
'
Set MyInboxItems = MyInbox.Items
'
For Each Mailobject In MyInboxItems
If Mailobject.UnRead Then

With TempRst

.AddNew
!Subject = Mailobject.Subject
!from = Mailobject.SenderName
!To = Mailobject.To
!Body = Mailobject.Body
!DateSent = Mailobject.SentOn
.Update
Mailobject.UnRead = False
End With
End If
Next
Set OlApp = Nothing
Set MyInbox = Nothing
Set MyInboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing
End Sub

Mavyak
08-11-2008, 12:14 PM
The full text is there, just not visible. Place your cursor at the bottom of a record marker until it turns to a double vertical arrow. Drag the row down to enlarge it and the rest of the text will be there.