Export emails from outlookfolder as one TXT file

  • Re: Export emails from outlookfolder as one TXT file


    I copied this from AndyPope and it loops and reads each email.


    Now, what i want is the extract all the information and place them on a textfile and save the textfile to my C:\ as opposed to importing into an sheet?


    Can anyone lead me in getting additional functionality into this code to do this?
    Anybody?


    Thanks in advance :)


    [vba]Public Sub ReadEmails()
    ' remember to include a reference to Outlook library

    Dim olApp As Outlook.Application
    Dim olNamespace As Outlook.Namespace
    Dim olFolder As Outlook.MAPIFolder
    Dim olMail As Outlook.MailItem
    Dim lngRow As Long
    Dim mydate


    Set olApp = New Outlook.Application
    Set olNamespace = olApp.GetNamespace("MAPI")

    ' Set olFolder = olNamespace.GetDefaultFolder(olFolderInbox)
    Set olFolder = olNamespace.Folders("Personal Folders")
    Set olFolder = olNamespace.Folders("Bloomberg")
    Set olFolder = olFolder.Folders("Brokers")


    lngRow = 1
    For Each olMail In olFolder.Items
    If olMail.ReceivedTime < mydate Then

    'HOW DO I ADD CODE HERE TO EXPORT TO C:\rawdata.txt???


    End With
    Else
    End If

    Next

    Set olMail = Nothing
    Set olFolder = Nothing
    Set olNamespace = Nothing
    Set olApp = Nothing
    End Sub[/vba]

  • Re: Export emails from outlookfolder as one TXT file


    You can try this

    Code
    SaveFileAs Filename:="C:\name.txt"


    but of course untested.

    [SIZE=2]I should change my name to STUMBED![/SIZE]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!