I'm trying to modify the following code to use it as rule Script but for some reason I can not figure it out how to modify the following line
here is the full code
Code:
For Each Item In Application.ActiveExplorer.Selection
here is the full code
Code:
Option Explicit
Public Sub UpdateReport(Item As Outlook.MailItem)
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim vText As Variant
Dim sText As String
Dim vItem As Variant
Dim i As Long
Dim rCount As Long
Dim bXStarted As Boolean
Dim FileName As String
Dim FilePath As String '// SaveAs CSV File Path
Dim sPath As String '// .CSV File Path
'// the path of the workbook
sPath = "C:\temp\temp.csv"
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Application.StatusBar = "Please wait while Excel source is opened ... "
Set xlApp = CreateObject("Excel.Application")
bXStarted = True
End If
' On Error GoTo 0
'// Open the workbook to input the data
Set xlWB = xlApp.Workbooks.Open(sPath)
Set xlSheet = xlWB.Sheets("Oracle Order")
'// Process Mail Item in ?
For Each Item In Application.ActiveExplorer.Selection
sText = Item.Body
vText = Split(sText, Chr(13)) ' Chr(13)) carriage return
'// Find the next empty line of the worksheet
rCount = xlSheet.Range("B" & xlSheet.Rows.Count).End(xlUp).Row
rCount = rCount + 1
'// Check each line of text in the message body
For i = UBound(vText) To 0 Step -1
'// Customer
If InStr(1, vText(i), "Customer") > 0 Then
vItem = Split(vText(i), Chr(9)) ' Chr(9) horizontal tab
xlSheet.Range("A" & rCount) = Trim(vItem(1))
End If
'// Order #
If InStr(1, vText(i), "Order #") > 0 Then
vItem = Split(vText(i), Chr(9))
xlSheet.Range("B" & rCount) = Trim(vItem(1))
End If
'// Service Level
If InStr(1, vText(i), "Service Level") > 0 Then
vItem = Split(vText(i), Chr(9))
xlSheet.Range("J" & rCount) = Trim(vItem(1))
End If
Next i
FilePath = Environ("USERPROFILE") & "\Documents\Temp\"
FileName = Sheets(1).Range("B2").Value
xlWB.SaveAs FileName:=FilePath & FileName
Next Item
'// Close & SaveChanges
xlWB.Close SaveChanges:=True
If bXStarted Then
xlApp.Quit
End If
Set xlApp = Nothing
Set xlWB = Nothing
Set xlSheet = Nothing
Set Item = Nothing
End Sub