-
Any clue if it is possible, and if so how to check for a message in your inbox for a particular subject and then write the message to a text file somewhere on your hard drive?
Please only replies from people that have an idea how to do it. No "check the object browser" type responses.
Thanks.
-
this uses the Outlook 8.0 object libriary:
Code:
Sub ReadEmail()
Dim oApp As Outlook.Application
Dim oNameSpace As Outlook.NameSpace
Dim oFolder As Outlook.MAPIFolder
Dim oMailItem As Object
Dim sMessage As String
Set oApp = New Outlook.Application
Set oNameSpace = oApp.GetNamespace("MAPI")
Dim Filename As String
Dim fnum As Byte
oNameSpace.Logon "MyProfile", , False, True
Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox)
For Each oMailItem In oFolder.Items
With oMailItem
If oMailItem.UnRead = True Then
If UCase(oMailItem.Subject) = "WHATEVER" Then
Debug.Print oMailItem.Body
'create a unique file name
Filename = "C:\MailText" & Format(Now, "yymmddhhnnss") & ".txt"
fnum = FreeFile
Open Filename For Binary As fnum
Put #fnum, , oMailItem.Body
Close fnum
End If
End If
End With
Next oMailItem
Set oMailItem = Nothing
Set oFolder = Nothing
Set oNameSpace = Nothing
Set oApp = Nothing
End Sub
-
Thanks
You are quite awesome, that worked great!
Thanks!!!!!!!!
-
Permission denied
Hi. I copied the exact code and tried running the program. I get an error message "permission denied". I'm under the impression that I have administrative rights. Thanks.