hmltnangel
07-29-2014, 07:26 AM
Ok, been using a quick bit of VBA with some help from folks on here to count emails from individuals.
It works great but I'm now needing to amend it a tiny bit to only count things in the last 7 days.
Keep getting error messages with this -
Sub CountItems1()
Dim pos() As Integer, cnt() As Integer
listofnames = Array("Dave", "Fred", "Jim", "Alan", "Claire") ' get array of names from whereever
ReDim pos(UBound(listofnames))
ReDim cnt(UBound(listofnames))
Set folderitems = ActiveExplorer.CurrentFolder.Items ' change folder to suit, if it not the active one
For Each mitem In folderitems
If DateDiff("d", msg.SentOn, Now) <= 7 Then
strt = Len(mitem.Body)
For i = 0 To UBound(pos)
pos(i) = InStrRev(mitem.Body, listofnames(i), strt)
If pos(i) > 0 Then strt = pos(i): firstfnd = listofnames(i)
Next
For i = 0 To UBound(listofnames)
If listofnames(i) = firstfnd Then cnt(i) = cnt(i) + 1: Exit For
Next
For i = 0 To UBound(listofnames)
msg = msg & listofnames(i) & " count of emails = " & cnt(i) & vbNewLine
Next
MsgBox msg 'for testing only, you could add each to an array for later processing
End Sub
It highlights my last End Sub ..... and says Block If Without End If.
Anyone any ideas :)
It works great but I'm now needing to amend it a tiny bit to only count things in the last 7 days.
Keep getting error messages with this -
Sub CountItems1()
Dim pos() As Integer, cnt() As Integer
listofnames = Array("Dave", "Fred", "Jim", "Alan", "Claire") ' get array of names from whereever
ReDim pos(UBound(listofnames))
ReDim cnt(UBound(listofnames))
Set folderitems = ActiveExplorer.CurrentFolder.Items ' change folder to suit, if it not the active one
For Each mitem In folderitems
If DateDiff("d", msg.SentOn, Now) <= 7 Then
strt = Len(mitem.Body)
For i = 0 To UBound(pos)
pos(i) = InStrRev(mitem.Body, listofnames(i), strt)
If pos(i) > 0 Then strt = pos(i): firstfnd = listofnames(i)
Next
For i = 0 To UBound(listofnames)
If listofnames(i) = firstfnd Then cnt(i) = cnt(i) + 1: Exit For
Next
For i = 0 To UBound(listofnames)
msg = msg & listofnames(i) & " count of emails = " & cnt(i) & vbNewLine
Next
MsgBox msg 'for testing only, you could add each to an array for later processing
End Sub
It highlights my last End Sub ..... and says Block If Without End If.
Anyone any ideas :)