Copying the whole e-mail body into excel

Status
Not open for further replies.

elbrodero

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
I am currently trying to figure out how to copy an e-mail text (from my newest unread mail) into excel. Manually it works just fine but I would like a code to do it.

I have the following code:

Const olFolderInbox As Integer = 6
Const AttachmentPath As String = "Y:\Do\"


Sub Avis7()

Dim task
Dim olNamespace As Object
Dim olApp As Object
Dim olNs As Object
Dim olFolder As Object
Dim olRecip As Object
Dim oOlItm As Object
Dim oOlAtch As Object
Dim oldsubject As String
Dim strBody As String


Dim y As Workbook
Set y = ThisWorkbook

Dim Str As String
Dim Str1 As String
Dim Str2 As String
Dim j As Integer
Dim i As Integer
Dim k As Integer




Set olApp = GetObject(, "Outlook.application")
Set olNs = olApp.GetNamespace("MAPI")
Set olRecip = olNs.CreateRecipient("bbb@bb.com")
Set olFolder = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox).Folders("09")


If olFolder.Items.Restrict("[UnRead] = True").Count = 0 Then
MsgBox "no unread mail"
Exit Sub
End If

For Each oOlItm In olFolder.Items.Restrict("[UnRead] = True")

If oOlItm.SenderEmailAddress = "hello@google.de" Then
strBody =oOlItm .body
y.Sheets(1).Range("A1") = strBody
End If

Next

End Sub


Unfortunately, absolutely nothing happens when I execute the code. Not even an error message.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Outlook changes the "Modified" field when moving/copying a Contact. Using Outlook 0
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
P Copying ALL calendar entries from Calender in PST file to IMAP OST file? Using Outlook 1
R VBA for copying sent email to current folder under a shared mailbox Outlook VBA and Custom Forms 17
E Copying data from e-mail attachement to EXCEL file via macro Outlook VBA and Custom Forms 38
T Copying Outlook Account Setup For Desktop App Using Outlook 5
J Outlook - 2013 - Error msg when copying folders from Online Archives to another user's mailbox Using Outlook 0
Thiago Manzano Copying E-mails to a folder on HD Using Outlook 1
Diane Poremsky Mark Sent Items as Read After Copying with a Rule Using Outlook 0
crazyboy Copying BCM database from backed up mounted image to new drive BCM (Business Contact Manager) 2
oliv- Prevent copying shared contacts Outlook VBA and Custom Forms 5
Paul Butticaz Copying Contacts from SharePoint List (connected to Outlook) to another Conacts folder Using Outlook 1
K Outlook 2010 Not responding after IMAP folder deletion or copying. Using Outlook 2
Mary B Outlook 2013: Rule for copying new email to folder & marking that copy as read Using Outlook 1
S Calendar items are not being uploaded to outlook.com after copying Using Outlook.com accounts in Outlook 1
P open reminders missing after copying outlook pst file Using Outlook 2
L Copying Emails using drag and drop Using Outlook 2
O New to Outlook 2013, dealing with copying vs. moving sent items Using Outlook 0
S Recover messages that disappeared when copying to folder Using Outlook 1
S Copying multiple messages to folders and keeping date/time detail Using Outlook 1
D Copying POP3 folders from Inbox to IMAP Inbox in Outlook 2003 Using Outlook 0
M Copying setups for mutiple users Using Outlook 2
T Location and simple copying of emails and settings, OL 2010 and Win 7 64bit. Using Outlook 3
A Copying additional contact fields when chosing "Contact from the same company" Using Outlook 5
A Copying cc email addresses to Excel - does not copy the <joe.bloggs@isp.com> Using Outlook 1
S Search Indexing (Copying Folders) Using Outlook 0
E Copying multiple folders to PST Outlook VBA and Custom Forms 2
B Copying data between atbs in a custom form Outlook VBA and Custom Forms 4
R copying a custom view from a public folder and distributing programatically Outlook VBA and Custom Forms 3
N error when copying outlook data "can not copy: the path too deep" Using Outlook 6
N Copying outlook macros between pcs Outlook VBA and Custom Forms 1
R Copying Data from Exchange to PST file Outlook VBA and Custom Forms 1
V Copying contents from one field to another field Outlook VBA and Custom Forms 6
V Calendar - Clearing the whole Calendar Using Outlook 1
P Limited Support for 3rd Party Mail in new Outlook? Using Outlook 1
T Exchange Server - Mail Delay Stamping Exchange Server Administration 0
L Error when exporting Sent Mail to Excel Outlook VBA and Custom Forms 6
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
K How can I delete an e-mail from Outlook Using Outlook 1
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
A Macro Mail Alert Using Outlook 4
e_a_g_l_e_p_i MY Outlook 2021 changed the format of the shortcuts for mail, calendar etc. Using Outlook 10
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
D Gmail mail is being delivered to a different email inbox in Outlook App 2021 Using Outlook 2
P What is your strategy for dealing with SPAM and Junk Mail? Using Outlook 1
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
T 1:1 Datatransfer from incoming mail body to customs form body Outlook VBA and Custom Forms 0
O Mail rule issue Using Outlook 3
A manual rule sends mail to wrong folder Using Outlook 5

Similar threads

Back
Top