I am currently trying to use this vba code and am running in to an issue with it saying the line of
Set outlooknamespace = OutlookApp.GetNamespace("MAPI") is not working and I can not figure out why.
Sub getDataFromOutlook()
Dim OutlookApp As Outlook.Application
Dim OutlookNameSpace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Set OutlookApp = New Outlook.Application
Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNameSpace.GetDefaultFoler(olFolderInbox).Folders("DDQ")
i = 1
For Each OutlookMail In Folder.Items
If OutlookMail.ReceivedTime >= Range("Email_Receipt_Date").Value Then
Range("email_subject").Offset(i, 0) = OutlookMail.Subject
Range("email_subject").Offset(i, 0).Columns.AutoFit
Range("email_subject").Offset(i, 0).VerticalAlignmant = xlTop
Range("email_Date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("email_Date").Offset(i, 0).Columns.AutoFit
Range("email_Date").Offset(i, 0).VerticalAlignment = xlTop
Range("email_Sender").Offset(i, 0).Value = OutlookMail.SenderName
Range("email_Sender").Offset(i, 0).Columns.AutoFit
Range("email_Sender").Offset(i, 0).VertricalAlignment = xlTop
Range("email_Body").Offset(i, 0).Value = OutlookMail.Body
Range("email_Body").Offset(i, 0).Columns.AutoFit
Range("email_Body").Offset(i, 0).VertricalAlignment = xlTop
i = i + 1
End If
Next OutlookMail
Set Folder = Nothing
Set OutlookNameSpace = Nothing
Set OutlookApp = Nothing
End Sub
any help or suggestions would be appreciated. I got this code from a video I saw
https://www.youtube.com/redirect?event=video_description&v=35g8J2mzdUY&redir_token=NxwnH_VmKtwOzqqPD_QZBTjc3q58MTU2NjA0ODU3NUAxNTY1OTYyMTc1&q=https%3A%2F%2Fwww.exceltrainingvideos.com%2Fget-data-from-outlook-into-excel-worksheet%2F
I am trying to get the Information from a sub folder titled DDQ under my Inbox. Not sure if that helps of not.
Thank you.