I'm using Excel 2007.I'm trying to retrive the body of messages inside a folder called Erika to an Excel sheet. The code run without errors but does not parse. As I step through the code my ParseTextLinePair is always "". Can anyone help me?
Code:
Sub Outlook_strip_all_data_to_excel()
Dim Fldr As MAPIFolder
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.Namespace
Dim myRecipient As Outlook.Recipient
Dim olMail As Variant
Dim i As Integer
Dim strIndex As String
Dim strEnterprise As String
Dim strCommercial As String
Dim strPublic As String
Dim strBasic_Silver As String
Dim strIPS As String
Dim strEDT As String
Dim strPS As String
Dim strSales_SAM As String
Application.ScreenUpdating = False
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myRecipient = myNamespace.CreateRecipient("Mailbox - Rodriguez, Angel - Authorized Dell Representative - Outlook Today")
myRecipient.Resolve
On Error Resume Next
Set mbox = myNamespace.Folders("Mailbox - Rodriguez, Angel - Authorized Dell Representative- Outlook Today")
Set inbox = mbox.Folders("Inbox")
Set Fldr = mbox.Folders("Erika")
i = 6
' i used for starting row in spreadsheet
For Each olMail In Fldr.Items
If InStr(olMail.Body, "a") > 0 Then
ActiveSheet.Cells(i, 1).Value = olMail.ReceivedTime
' Each string below is a data item in the email
strIndex = ParseTextLinePair(olMail.Body, "Index: ")
strEnterprise = ParseTextLineDown(olMail.Body, "Enterprise", ") on")
strCommercial = ParseTextLinePair(olMail.Body, "Commercial: ")
strBasic_Silver = ParseTextLinePair(olMail.Body, "Basic_Silver: ")
strIPS = ParseTextLinePair(olMail.Body, "IPS: ")
strEDT = ParseTextLinePair(olMail.Body, "EDT: ")
strPS = ParseTextLinePair(olMail.Body, "PS: ")
strSales_SAM = ParseTextLinePair(olMail.Body, "Sales_SAM: ")
strClient = ParseTextLinePair(olMail.Body, "Client: ")
strCommercial = ParseTextLinePair(olMail.Body, "Commercial: ")
strPublic = ParseTextLinePair(olMail.Body, "Public: ")
'input to spreadsheet, all on same row next to received time
ActiveSheet.Cells(i, 2).Value = strIndex
ActiveSheet.Cells(i, 3).Value = strEnterprise
ActiveSheet.Cells(i, 4).Value = strCommercial
ActiveSheet.Cells(i, 5).Value = strBasic_Silver
ActiveSheet.Cells(i, 6).Value = strIPS
ActiveSheet.Cells(i, 7).Value = strEDT
ActiveSheet.Cells(i, 9).Value = strPS
ActiveSheet.Cells(i, 10).Value = strSales - SAM
ActiveSheet.Cells(i, 11).Value = strClient
ActiveSheet.Cells(i, 12).Value = strCommercial
ActiveSheet.Cells(i, 13).Value = strPublic
'ActiveSheet.Cells(i, 14).Value = strSamCarTwo
i = i + 1
End If
Next olMail
Range("H3").Select
MsgBox "Completed Outlook Strip"
End Sub
Function ParseTextLinePair(strSource As String, strLabel As String)
Dim intLocLabel As Integer
Dim intLocCRLF As Integer
Dim intLenLabel As Integer
Dim strText As String
' locate the label in the source text
intLocLabel = InStr(strSource, strLabel)
intLenLabel = Len(strLabel)
If intLocLabel > 0 Then
intLocCRLF = InStr(intLocLabel, strSource, vbCrLf)
If intLocCRLF > 0 Then
intLocLabel = intLocLabel + intLenLabel
strText = Mid(strSource, _
intLocLabel, _
intLocCRLF - intLocLabel)
Else
intLocLabel = Mid(strSource, intLocLabel + intLenLabel)
End If
End If
ParseTextLinePair = Trim(strText)
End Function
[code]