• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Copying the whole e-mail body into excel

elbrodero

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
#1
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.
 

Similar threads