Solved

Macro to read email.

Posted on 2001-07-17
2
218 Views
Last Modified: 2012-08-13
Hi,

I need to be able read the content of every message in a folder - the folder will always be the same so it can be hard coded.

(I intended to dump this info to a text file - I can do this bit!)

Cheers

Rupert
0
Comment
Question by:ruperts
2 Comments
 
LVL 2

Accepted Solution

by:
Paullkha earned 100 total points
ID: 6298979
Option Compare Database
Option Explicit

Private olapp As Outlook.Application
Private olns As Outlook.NameSpace

'****************************************
'With this code, folder can be "anywhere"
'****************************************
Private Function MessageFldrExists() As Outlook.MAPIFolder
On Error GoTo err_DNE
    Dim olFolders As Outlook.MAPIFolder
   
    Set olFolders = olns.Folders("Personal Folders")
    Set MessageFldrExists = olFolders.Folders("MessageMail")
   
    Exit Function
   
err_DNE:
    Set MessageFldrExists = Nothing
End Function
Private Sub olLogon()
    Set olapp = New Outlook.Application
    Set olns = olapp.GetNamespace("MAPI")
    olns.Logon
   'dont proceed until logged on
   DoEvents
End Sub

Private Sub olLogoff()
    DoEvents
   'dont quit until all finished
    olns.Logoff
    Set olns = Nothing
    Set olapp = Nothing
End Sub

Private Sub MessageFldr2Table()
Dim Messagefldr As Outlook.MAPIFolder
Dim itmMail As Outlook.MailItem
Dim itmsMail As Outlook.Items
Dim strBody As String
   
    Call olLogon
    Set Messagefldr = MessageFldrExists()
    If Not (Messagefldr Is Nothing) Then
        Set itmsMail = Messagefldr.Items
        For Each itmMail In itmsMail
'****************
'Here is the place to put in sending strBody to a file
'****************
            strBody = itmMail.Body
        Next
    End If
    Call olLogoff
End Sub
=========
Note:
You must have a reference to Outlook object set somewhere.



0
 

Expert Comment

by:PandoraMod
ID: 6366486
ruperts, are you still having a problem? If so, please provide more information. If you solved your problem, please let us know how and then we can archive this.

Thanks,
PandoraMod
Moderator @ Experts Exchange
e-mail: pandoramod@experts-exchange.com
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question