Import_mail function gives error on office 2019

%3CLINGO-SUB%20id%3D%22lingo-sub-2619594%22%20slang%3D%22en-US%22%3EImport_mail%20function%20gives%20error%20on%20office%202019%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2619594%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20I%20have%20a%20problem%20with%20importing%20mails%20from%20outlook%20on%20excel%20(2019)%20in%20vba.%3CBR%20%2F%3EThe%20code%20below%20works%20perfectly%20on%20excel%202016%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3ESub%20ImportEMail()%0ADim%20olA%20As%20Outlook.Application%0ADim%20olNS%20As%20Outlook.Namespace%0ADim%20olF%20As%20Outlook.MAPIFolder%0ADim%20olM%20As%20Outlook.MailItem%0A%0ADim%20iRow%20As%20Integer%0A%0ASet%20olA%20%3D%20New%20Outlook.Application%0ASet%20olNS%20%3D%20olA.GetNamespace(%22MAPI%22)%0A%0ASet%20olF%20%3D%20olNS.PickFolder%0A%0AiRow%20%3D%201%0AFor%20Each%20olM%20In%20olF.Items%0AWith%20ActiveSheet%0A'.Cells(iRow%2C%201)%20%3D%20olM.SenderName%0A'.Cells(iRow%2C%201)%20%3D%20olM.SenderEmailAddress%0A.Cells(iRow%2C%202)%20%3D%20olM.ReceivedTime%0A.Cells(iRow%2C%203)%20%3D%20olM.Subject%0A'.Cells(iRow%2C%204)%20%3D%20olM.Body%0A%0AiRow%20%3D%20iRow%20%2B%201%0AEnd%20With%0ANext%0A%0ASet%20olM%20%3D%20Nothing%0ASet%20olF%20%3D%20Nothing%0ASet%20olNS%20%3D%20Nothing%0ASet%20olA%20%3D%20Nothing%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2619594%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2619751%22%20slang%3D%22en-US%22%3ERe%3A%20Import_mail%20function%20gives%20error%20on%20office%202019%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2619751%22%20slang%3D%22en-US%22%3Ewith%20rem%20removed%20on%20sendername%2C%20senderemailaddress%2C%20body%3CBR%20%2F%3E%3CBR%20%2F%3Ewhen%20I%20put%20it%20on%20office2019%20it%20gives%20me%20this%20error%20for%20all%20the%20fields%20where%20I%20put%20the%20rem...%20...strange%20but%20it%20only%20correctly%20takes%20Receivedtime%20and%20subject%3CBR%20%2F%3E%3CBR%20%2F%3ERun-time%20error%20'-2147467259%20(80004005)'%3A%3CBR%20%2F%3EMethod%20'SenderName'%20of%20object%20'_MailItem'%20failed%3CBR%20%2F%3E%3CBR%20%2F%3EWho%20can%20help%20me%20solve%20this%20mystery%3F%3CBR%20%2F%3EI%20can't%20understand%20the%20functions%20that%20work%20halfway.%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20in%20advance%20to%20all%3C%2FLINGO-BODY%3E
New 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