MarkBickers
New Member
- Joined
- Nov 3, 2023
- Messages
- 1
- Office Version
- 2010
Hi Excel Experts,
Hi There,
I am looking for excel vba code to check the emails in a subfolder in Outlook mailbox and get the following details from the body of the email and save down in excel sheet .
Please see below the content of email body.
The format of the emails will be same for all in that particular subfolder . I have used "Sheet1" in excel workbook to store Mailbox name and the subfolder name so the code will look for those values in sheet1 and loops through all the emails in the subfolder and save down all the details in Sheet2 . Can anyone please amend the code and make it work as I am getting an error message "Method 'Body' of object '_MailItem" failed on the lines highlighted as red
Thanks,
Mark
Hi There,
I am looking for excel vba code to check the emails in a subfolder in Outlook mailbox and get the following details from the body of the email and save down in excel sheet .
Please see below the content of email body.
The format of the emails will be same for all in that particular subfolder . I have used "Sheet1" in excel workbook to store Mailbox name and the subfolder name so the code will look for those values in sheet1 and loops through all the emails in the subfolder and save down all the details in Sheet2 . Can anyone please amend the code and make it work as I am getting an error message "Method 'Body' of object '_MailItem" failed on the lines highlighted as red
Code:
Sub GetFromOutlook()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Dim msgtext As String
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("New Apps")
i = 1
lrow = 1
For Each OutlookMail In Folder.Items
MsgBox Folder.Items.Count
msgtext = OutlookMail.Body
MsgBox msgtext
With ActiveSheet
.Cells(lrow, 1) = OutlookMail.SenderName
.Cells(lrow, 2) = OutlookMail.Subject
.Cells(lrow, 3) = OutlookMail.ReceivedTime
lrow = lrow + 1
End With
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
Thanks,
Mark