Import_mail function gives error on office 2019

Copper Contributor

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

 

1 Reply
with rem removed on sendername, senderemailaddress, body

when I put it on office2019 it gives me this error for all the fields where I put the rem... ...strange but it only correctly takes Receivedtime and subject

Run-time error '-2147467259 (80004005)':
Method 'SenderName' of object '_MailItem' failed

Who can help me solve this mystery?
I can't understand the functions that work halfway.

Thanks in advance to all