PDA

View Full Version : [SOLVED:] Custom Field - loop through each email and add the value?



TrippyTom
08-23-2013, 01:49 AM
Hi gang,

I know very little about vba for Outlook. But I'm hoping there is a simple solution to my question:
I am using Outlook 2010 at work, and made a custom field called "Estimate" that I formatted as a "2 Decimal: 1,234.57"

Is there a way to show the SUM of all my messages with that value somehow? If not, could it be a simple vba solution? Maybe show the total in the status bar of any message selected (or all messages)?

Thanks in advance for anything that might point me in the right direction. I can't figure out how to use the search feature (seems to hang for me), so apologies if this was already covered.

-Tom

TrippyTom
08-28-2013, 02:17 AM
Well, after trudging through the Microsoft help system, I managed to put together something that works. I don't think it's worthy of posting here, since all I did was modify the help system code to fit my needs. Once I figured out how to access my custom field through the object model, it was easy.

Thanks anyway. :)

TrippyTom
08-28-2013, 03:15 AM
Nevermind, I'll post the code, although I had to keep the "on error resume next" in there or it would error out and I don't know why.


Sub EstimateCount()
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim oMail As Outlook.MailItem
Dim MsgEst As Double, tmpValue As Double
Dim x As Long
On Error Resume Next
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
tmpValue = 0

For x = 1 To myOlSel.Count
If myOlSel.Item(x).Class = OlObjectClass.olMail Then
Set oMail = myOlSel.Item(x)
MsgEst = oMail.ItemProperties.Item("Estimate") '<--- My custom field name here
If oMail.ItemProperties.Item("Estimate") = 0 Then
MsgEst = 0
ElseIf oMail.ItemProperties.Item("Estimate") = "" Then
MsgEst = 0
End If
tmpValue = tmpValue + MsgEst
End If
Next x
MsgBox ("Total Estimate: " & Format$(tmpValue, "0.00"))
End Sub

10510