Hi Guys
Im hoping someone is able to help I havent worked with VBA for some time. I have written some script to try and search a specific folder in my inbox and find emails with a specific subject. Once these emails are located I want them to populate the information into the excel document. An example of the code im using is below.
Code
Sub GetFromOutlook()
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.GetDefaultFolder(olFolderInbox).Folders("Mon").Folders("Alerts")
i = 1
For Each OutlookMail In Folder.Items
If OutlookMail.Subject = "Alarm notification" Then
Range("eMail_subject").Offset(i, 0).Value = OutlookMail.Subject
Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("eMail_text").Offset(i, 0).Value = OutlookMail.Body
i = i + 1
End If
Next OutlookMail
Set OutlookApp = Nothing
Set OutlookNamespace = Nothing
Set Folder = Nothing
End Sub
Display More
The above code runs but never actually does anything so errors but nothing populates in the excel sheet. Have I missed a step or can anyone see anything I may have missed?