Transfer Outlook Email to Excel and its Attachment to Drive C
Hi,
I am new to VBA and I am trying to look for a solution in solving below codes. I would like to transfer the email to excel when I enter a specified date. If it has attachment, it will save on Drive C/Email Attach/. I have search it in google however there are bugs which I can't understand. I am encountering an error that says, " Run-time error 424 Object Required" under the line "Range("Email_Subject").offset(1,0).Value = Outlookmail.Subject". I would also be very grateful if you could also add the attachment code to it. Please if anyone there who could help, please help me. I would be very much grateful for that. You may revised my work if you think it is not the correct one.
Code:
Dim olApp as Outlook.Application
Dim olNS as Outlook.Namespace
Dim olFldr as Outlook.MAPIFolder
Dim OlItms as Outlook.Items
Dim olMail as Variant
Dim 1 as Integer
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace ("MAPI")
Set OlFldr = olNS.Pickfolder
if olFldr = "Nothing" then Exit sub
Set olItms = olFldr.Items
i = 1
if olItms.ReceivedTime >= Range("B4").value then
Range("Email_Subject").offset(1,0).Value = Outlookmail.Subject
Range("Email_Date").offset(1,0).Value = Outlookmail.ReceivedTime
Range("Email_Sender").offset(1,0).Value = Outlookmail.SenderName
Range ("Email_Body").offset(1,0).Value = Outlookmail.body
i = 1 + 1
else
endif
Range("A:D").EntireColumn.Autofit
Set Folder = Nothing
Set olFldr = Nothing
Set olApp = Nothing
End Sub
Thanks