Aug 06 2021 05:48 AM
Hi, I have a problem with importing mails from outlook on excel (2019) in vba.
The code below works perfectly on excel 2016:
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
Aug 06 2021 06:30 AM