Thanks for your reply. My reference to "certain" MailItems was intended to mean properties of Outlook not particular e-mails. For instance if the below code is used, it works fine. Also, I am choosing a folder which only has e-mails in it (it doesn't have any meeting notices, etc.)
Sub ImportEMail()
Dim olA As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olF As Outlook.MAPIFolder
Dim olM As Outlook.MailItem
Dim iRow As Integer
Set olA = New Outlook.Application
Set olNS = olA.GetNamespace("MAPI")
Set olF = olNS.PickFolder
iRow = 1
For Each olM In olF.Items
With ActiveSheet
'.Cells(iRow, 1) = olM.SenderName
'.Cells(iRow, 1) = olM.SenderEmailAddress
.Cells(iRow, 2) = olM.ReceivedTime
.Cells(iRow, 3) = olM.Subject
'.Cells(iRow, 4) = olM.Body
iRow = iRow + 1
End With
Next
Set olM = Nothing
Set olF = Nothing
Set olNS = Nothing
Set olA = Nothing
End Sub
But if the lines with "SenderName, SenderEmailAddress, and Body" are added back in, I get the errors referenced in my previous post.
Also, the below code doesn't work either and contains a specific reference to mail items (the line with "If objItem.Class = olMail"), so I don't think the class of the item is the issue.
Option Explicit
Private Sub CommandButton1_Click()
On Error GoTo ErrHandler
' Set Outlook application object.
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
Dim objNSpace As Object ' Create and Set a NameSpace OBJECT.
' The GetNameSpace() method will represent a specified Namespace.
Set objNSpace = objOutlook.GetNamespace("MAPI")
Dim myFolder As Object ' Create a folder object.
Set myFolder = objNSpace.GetDefaultFolder(olFolderInbox)
Dim objItem As Object
Dim iRows, iCols As Integer
iRows = 2
' Loop through each item in the folder.
For Each objItem In myFolder.Items
If objItem.Class = olMail Then
Dim objMail As Outlook.MailItem
Set objMail = objItem
Cells(iRows, 1) = objMail.SenderEmailAddress
Cells(iRows, 2) = objMail.To
Cells(iRows, 3) = objMail.Subject
Cells(iRows, 4) = objMail.ReceivedTime
End If
iRows = iRows + 1
Next
Set objMail = Nothing
' Release.
Set objOutlook = Nothing
Set objNSpace = Nothing
Set myFolder = Nothing
ErrHandler:
Debug.Print Err.Description
End Sub
Thanks again for your assistance.
Bookmarks