Question : I wanted to parse out text in outlook using VBA and save the values in a spread sheet

Hi,

I have a message and a text field as shown in the attached picture. These are from OnTime, a product from Axasoft.

I want to

1) Parse out this email  and extract the incident number using VBA (2000 in this example)
2) Pase the emal and extract the status (Pending Development)
3) Append the text "incident number", "status" to a text file

I assume this would require VBA, but any approach that works is fine.

Answer : I wanted to parse out text in outlook using VBA and save the values in a spread sheet

Here's my solution.  Follow these instructions to add the code to Outlook.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor

To use this

1.  Select or open a message
2.  Run the macro CShene

An alternative is to alter the code slightly to run it from a rule.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
Sub CShene()
    Dim olkMsg As Outlook.MailItem, strIncidentNumber As String, strStatus As String, varLine As Variant, _
        arrLine As Variant, objFSO As Object, objFile As Object
    Select Case TypeName(Application.ActiveWindow)
        Case "Explorer"
            Set olkMsg = Application.ActiveExplorer.Selection(1)
        Case "Inspector"
            Set olkMsg = Application.ActiveInspector.CurrentItem
    End Select
    For Each varLine In Split(olkMsg.Body, vbCrLf)
        arrLine = Split(varLine, ":")
        If UBound(arrLine) > 0 Then
            Select Case arrLine(0)
                Case "Incident Number"
                    strIncidentNumber = arrLine(1)
                Case "Status"
                    strStatus = arrLine(1)
                    Exit For
            End Select
        End If
    Next
    Set objFSO = CreateObject("Scripting.FileSystemobject")
    'On the next line change the file name and path.'
    Set objFile = objFSO.OpenTextFile("C:\eeTesting\CShene.txt", ForAppending, True)
    objFile.WriteLine GetPrintable(strIncidentNumber) & "," & GetPrintable(strStatus)
    objFile.Close
    Set objFSO = Nothing
    Set objFile = Nothing
End Sub

Function GetPrintable(strValue As String) As String
    Dim intCount As Integer, strTemp As String
    For intCount = 1 To Len(strValue)
        strTemp = Mid(strValue, intCount, 1)
        Select Case Asc(strTemp)
            Case 32 To 126
                GetPrintable = GetPrintable & strTemp
        End Select
    Next
    GetPrintable = Trim(GetPrintable)
End Function
Random Solutions  
 
programming4us programming4us