have to read undelivered e-mail messages from outlook inbox and store in a text file. i am total newbie in VBA. so plz help.
Here is my code.
Public Sub ProcessInbox()
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim iMsgCount As Integer
Dim oMessage As Outlook.ReportItem
Dim iCtr As Long, iAttachCnt As Long
Set oOutlook = New Outlook.Application
Set oNs = oOutlook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)
For Each oMessage In oFldr.Items
With oMessage
'basic info about message
If (oMessage.Subject) = "Undeliverable" Then
Debug.Print .To
Debug.Print .CC
Debug.Print .Subject
Debug.Print .Body
iMsgCount = iMsgCount + 1
'save message as text file
.SaveAs "C:\message" & iMsgCount & ".txt", olTXT
end if
End With
DoEvents
Next oMessage
Set oAttachment = Nothing
Set oAttachments = Nothing
Set oMessage = Nothing
Set oFldr = Nothing
Set oNs = Nothing
Set oOutlook = Nothing
End Sub
At this line
For Each oMessage In oFldr.Items
i am getting error run-time error 13 type mismatch