Question : How to use Outlook VBA to select messages in an Outlook folder and run VBA macro

This is a follow up to solution: http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26357973.html

I would like to loop though all the messages in a specified mail folder and run that VBA macro in the previous solution against each mail message in that folder.

250 points for input that helps me
500 for working code.

Answer : How to use Outlook VBA to select messages in an Outlook folder and run VBA macro

Hello again, cschene.

This should do it.  Replace the subroutine named Cschene with the one below.  To use this

1.  Open the folder with the items you want to process
2.  Select the items to process.  CTRL+A will select them all
3.  Run the macro
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:
Sub CSchene()
    Const ForAppending = 8
    Dim olkMsg As Outlook.MailItem, strIncidentNumber As String, strStatus As String, varLine As Variant, _
        arrLine As Variant, objFSO As Object, objFile As Object
    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)
    For Each olkMsg In Application.ActiveExplorer.Selection
        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
        objFile.WriteLine GetPrintable(strIncidentNumber) & "," & GetPrintable(strStatus)
    Next
    objFile.Close
    Set objFSO = Nothing
    Set objFile = Nothing
    Set olkMsg = Nothing
    msgbox "Done"
End Sub
Random Solutions  
 
programming4us programming4us