A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Please help me parse this email



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 15th 07, 08:22 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Please help me parse this email

This is the problem:

Set objItem = GetCurrentItem()

The item returned by GetCurrentItem is totally unrelated to the new item received by Outlook that you're running this procedure to process, via a "run a script" rule action. In such a procedure, the item to be processed is passed as the parameter:


Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem
Dim rply as Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
CustName = ParseTextLinePair(msg.Body, "Owner = ")

Set msg = Nothing
Set rply = Nothing
Set olNS = Nothing
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Steve" wrote in message ...
I modified this code that I got from OutlookCode

But it doesn't appear to be parsing because I don't get the Message
box


Sub ParseValidationEmail(MyMail As MailItem)
Dim objItem As Object
Dim intLocAddress As Integer
Dim intLocCRLF As Integer
Dim Custemail As String
Dim CustName As String
Dim Product As String
Dim CustOrderDate As String
Dim CustValidationCode As String


Set objItem = GetCurrentItem()
If objItem.Class = olMail Then
' find the Order Info
Custemail = olMail.To
CustName = ParseTextLinePair(objItem.Body, "Owner = ")
Product = ParseTextLinePair(objItem.Body, "Program = ")
CustOrderDate = ParseTextLinePair(objItem.Body, "Validation Date =
")
CustValidationCode = ParseTextLinePair(objItem.Body, "Validation
Code = ")

MsgBox (Custemail)
MsgBox (CustName)
MsgBox (Product)
MsgBox (CustOrderDate)
MsgBox (CustValidationCode)
'MsgBox (strAddress)

End If

Set objReply = Nothing
Set objItem = Nothing
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

Function GetCurrentItem() As Object
Dim objApp As Outlook.Application

Set objApp = CreateObject("Outlook.Application")
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem =
objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
' anything else will result in an error, which is
' why we have the error handler above
End Select

Set objApp = Nothing
End Function

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any SDK to parse the outlook extend.dat file? IceKettle Add-ins for Outlook 4 January 17th 07 12:56 AM
Parse for URL's Zigman53 Outlook and VBA 2 October 15th 06 06:52 PM
Parse email headers John Smith Outlook and VBA 1 March 28th 06 08:46 PM
Parse .msg file Vadivel Outlook and VBA 5 March 16th 06 06:17 PM
Parse .msg file Vadivel Outlook - Using Forms 1 March 15th 06 04:26 PM


All times are GMT +1. The time now is 11:14 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.