Hi Westconn1
I am getting same error on Line
HTML Code:
mynumber = Mid(thebody, tot + 9, InStr(tot, thebody, "VENDOR") - tot - 9)
.
I think there is something which i am doing worng. Below is the code with changes i have done.
Suggest changes
HTML Code:
Sub Amount_Order()
'the folder you want to process
Dim myfolder As Outlook.Folder, less As Outlook.MAPIFolder, greater As Outlook.MAPIFolder
'the items in this folder
Dim myitems As Outlook.Items
'the item in the collection of items
Dim myitem As Object
'the no of the item in the loop
Dim itemno As Long
'the message in the loop
Dim mymessage As Outlook.MailItem
'the text of the message
Dim thebody As String
'mynumber is the amount of the order. Defined as double because
'we want to process the stuff after the decimal too
Dim mynumber As Double
'set folder to current selected active folder
Set myfolder = ActiveExplorer.CurrentFolder
Set less = myfolder.Folders("less than $100")
Set greater = myfolder.Folders("greater than $100")
'store the items of this folder in a container
Set myitems = myfolder.Items
'if greater than zero, do something
If myitems.Count = 0 Then
MsgBox "No emails in this folder."
Else
'backwards count
For itemno = myitems.Count To 1 Step -1
'TypeName(Item) = "MailItem"
'make sure it's a mailitem and nothing else (ie. read receipt or something else)
If TypeName(myitems.Item(itemno)) = "MailItem" Then
Set mymessage = myitems.Item(itemno)
'store the messagebody to the variable
thebody = mymessage.Body
'display it
'MsgBox thebody
'locate the start of the number in the message body and add 9 because
'we don't need the search string (TOTAL AMT) included
'then locate the end of the number you want. in this case I used VENDOR because
'that's the first word after the number you are after
'starting from the searchstring TOTAL AMT and we are going to
'substract 9 + the number where we found VENDOR (1st occurence after starting point
'from TOTAL AMT to determine the number
'
'check if email has TOTAL AMT phrase
'If InStr(1, thebody, "TOTAL AMT") <> 0 Then
tot = InStr(1, thebody, "TOTAL AMT")
If tot > 0 Then
mynumber = Mid(thebody, tot + 9, InStr(tot, thebody, "VENDOR") - tot - 9)
Else
MsgBox "TOTAL AMT not found"
End If
If mynumber < 101 Then
'less than $100
'MsgBox mynumber & " <= 100"
Set myitem = myitems.Item(itemno)
myitem.Move less
Else
'greater than $100
'MsgBox mynumber & " > 100"
Set myitem = myitems.Item(itemno)
myitem.Move greater
End If
Else
MsgBox "No mail with TOTAL AMT number."
End If
Next itemno
End If
End Sub
Thanks
------------------------------------