Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Read internal of e-mail via vba or vb (2000)

    i dont know....
    Is possible to read the internal text line by line of email witouth open it?
    In effect i have a body of email with a tabular data... and i want to get data similar a normal txt file.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    Here is an example. It is intended to be run within Outlook. It reads the first item in the Inbox and outputs the lines of the body of the e-mail to the Immediate window.

    Sub Test()
    Dim fld As MAPIFolder
    Dim itm As MailItem
    Dim strBody As String
    Dim arr() As String
    Dim i As Integer
    Set fld = Session.GetDefaultFolder(olFolderInbox)
    Set itm = fld.Items(1)
    strBody = itm.Body
    arr = Split(strBody, vbCrLf)
    For i = LBound(arr) To UBound(arr)
    Debug.Print arr(i)
    Next i
    End Sub

    You can replace the Debug.Print line with your own code to process the lines.

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    Hans as usual work fine! Tks.
    But i want to run the code via vba in a Excel module:-(
    In other case i know the sender address (ds.territoriosud@xxx.com)
    and to be sure, i wnat to scan all messages in my inbox, and use naturally the newest email with the sender address...
    Is possible?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    See the attached code.
    Attached Files Attached Files

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    Hans no words!!!!!!!!!!!!!!! tks for code, but with old code all work fine... in new code the macro go in error in:
    strBody = itm.Body
    and the error cointroll go in:
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    It means that the code hasn't found an e-mail with the sender name that you specified. You must use the sender name as displayed in Outlook.

  7. #7
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    But...
    I have send to me frorm me an email my email is: salvatore.imparato@xxx.com and if i substiituitre the line Set itm = its.Find("[SenderName]='salvatore.imparato@xxx.com'") the code go in error but if i substituite the set itm with Imparato Salvatore the code work SUPER FINE!!!!
    In effect i musta substituite the real name of sender and not the email address, or not?

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    You must use the display name of the sender exactly as it is shown in the From box of the e-mail.

  9. #9
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    ok Hans now all work fine... tks!
    dubt...
    But existis (in vba for excel) to loop in all folders in Outlook: personal, inbox,ecc... and find the email with the condition in first post?
    Because i dont know if the user have a rule to copy in other dir the email when recived it... this is a very strong prob(!?)

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    You can use code like this:

    Dim fld As MAPIFolder
    For Each fld In Session.GetDefaultFolder(6).Parent.Folders
    If fld.DefaultItemType = 0 Then
    ' code to process the items in the folder goes here
    End If
    Next fld

  11. #11
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    GOOD!

  12. #12
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    ... During the loop the code not scann the list of folders in read square(?!)

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    When you start with GetDefaultFolder, you are working inside your Exchange mailbox or primary PST. To access your Mailbox and all PSTs, start from the very top level. Here are two examples: Re: Using VBA to move a message to a PST file (Out, Re: Email folders & subfolders? (2002)

  14. #14
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    Tks for tips!
    But i have see in debug mode the value in line GetDefaultFolder(olFolderInbox) assume a number in olFolderInbox (in this acse assume 6) , i think is possible to set other dir by numeber similar GetDefaultFolder(6)... existis a comparison table to set other dir by number? for example Outbox wath is the correspendet number?

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Read internal of e-mail via vba or vb (2000)

    In addition to Jefferson's reply:

    Add the following to the declarations:

    Dim rfl As Object

    And change the code like this:

    Set nsp = app.GetNameSpace("MAPI")
    For Each rfl In nsp.Folders
    For Each fld In rfl.Folders
    Set its = fld.items
    ...
    Next fld
    Next rfl

Page 1 of 2 12 LastLast

Posting Permissions

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