Re: Scan Outlook emails for text and copy into xl
These emails are routed to one folder in my outlook based on sender's address. So all the emails with quotes stay in one sub folder among my personal folders. Here is an example (with names and prices changed of course) :nono: :
Some are like this (Showing only the subject):
"Microsoft trades
101.50 - 103.50"
Others:
> Pets.com - 101 5/8 : 102 $2 x $2
> ebay - 103 : 104 1/4 $2 x $2
> yahoo - 99 7/8 : 100 1/4 $2 x $2
> Insignia - 102 1/2 : 103 7/8 $2 x $2
The ">" may or may not be there and some times ":" to separate bid /ask is replaced by "-". I know the company names for example "Pets.com" to search on.
The space between the company name and the bid might be different.
I was able to pull the entire text of the emails into excel using this code, but got memory error. What needs to be done is to read these emails one by one parse and copy the data into excel and then the next email. Having parameters for date received will also be helpful:
[vba]Public Sub ReadEmails()
' remember to include a reference to Outlook library
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem
Dim lngRow As Long
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
' Set olFolder = olNamespace.GetDefaultFolder(olFolderInbox)
Set olFolder = olNamespace.Folders("Bloomberg")
Set olFolder = olFolder.Folders("Brokers")
'Set olFolder = olFolder.Folders("Brokers")
lngRow = 1
For Each olMail In olFolder.Items
With ActiveSheet
.Cells(lngRow, 1) = olMail.SenderName
.Cells(lngRow, 2) = olMail.Subject
.Cells(lngRow, 3) = olMail.Body
lngRow = lngRow + 1
End With
Next
Set olMail = Nothing
Set olFolder = Nothing
Set olNamespace = Nothing
Set olApp = Nothing
End Sub[/vba]
Thanks in advance