Consulting

Results 1 to 4 of 4

Thread: Importing multiple lines of text from outlook via vba

  1. #1
    VBAX Regular
    Joined
    Aug 2008
    Posts
    8
    Location

    Importing multiple lines of text from outlook via vba

    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,

  2. #2
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    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?

  3. #3
    VBAX Regular
    Joined
    Aug 2008
    Posts
    8
    Location
    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

  4. #4
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •