Email to excel

pratiksuhasaria

New Member
Joined
Mar 26, 2019
Messages
24
Hi All

I want to import mails from my outlook inbox to excel sheet depending on subject line i.e. if and only if subject line contains text APPROVED or CLARIFICATION at the start of subject.

Subject : APPROVED xyzz.....
CLARIFICATION abc.....

only this type of mail need to be extracted from inbox.

I have following code in which I need some this changes:
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)


i = 1
For Each OutlookMail In Folder.Items
With ThisWorkbook.Worksheets("TechnicalSheet").Range("B" & i + 1)
.NumberFormat = xlShortdate
.Value = DateValue(OutlookMail.ReceivedTime)
End With
ThisWorkbook.Worksheets("TechnicalSheet").Range("A" & i + 1).Value = OutlookMail.Subject
i = i + 1
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing


End Sub

Please help me
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try this

Code:
Sub GetFromOutlook()
  Dim OutlookApp As Outlook.Application, OutlookNamespace As Namespace
  Dim OutlookMail As Variant, i As Integer
  Set OutlookApp = New Outlook.Application
  Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
  i = 2
  For Each OutlookMail In OutlookNamespace.GetDefaultFolder(olFolderInbox).Items
    Select Case True
      Case UCase(OutlookMail.Subject) Like "*APPROVED*" Or UCase(OutlookMail.Subject) Like "*CLARIFICATION*"
        With ThisWorkbook.Worksheets("TechnicalSheet")
          .Range("A" & i).Value = OutlookMail.Subject
          .Range("B" & i).NumberFormat = xlShortdate
          .Range("B" & i).Value = DateValue(OutlookMail.ReceivedTime)
        End With
        i = i + 1
    End Select
  Next OutlookMail
  Set OutlookNamespace = Nothing
  Set OutlookApp = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top