 |
 |

02-24-2003, 03:50 AM
|
|
Centurion
|
|
Join Date: Jan 2003
Posts: 190
|
|
Counting messages
|
Anyway to count how many times an Email is addressed to this name in my Outlook messages?
***All PeopleEmail
I need it to count how many messages in my Outlook 2000 mail were
addressed to: ***All PeopleEmail
I assume it would have search all the emails and get the
information from the "To" field.
From: Front Office
To: ***All PeopleEmail
CC:
Subject: Junk Data
Is this possible?
|
|

02-24-2003, 11:31 AM
|
|
Newcomer
|
|
Join Date: Feb 2003
Location: Nor-Cal
Posts: 21
|
|
I believe this will help you out, however, I am sure that there is someone else that could do it in a graceful manner, instead of my hammering. Anyway here it is.
Code:
Public Sub CountMessages()
On Error GoTo ErrorHandler
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderSentMail)
Dim intCounter As Integer
Dim intLoop As Integer
intLoop = 0
Do
intLoop = intLoop + 1
Set myitem = myFolder.Items(intLoop)
If myitem.To = "***All PeopleEmail" Then
intCounter = intCounter + 1
End If
Loop While myitem <> "Nothing"
Exit Sub
ErrorHandler:
Select Case Err.Number ' Evaluate error number.
Case -2147352567 'Array index out of bounds
Set myitem = Nothing
MsgBox "***All PeopleEmail was emailed " & _
intCounter & " times."
Case Else
' Handle other situations here...
End Select
End Sub
This works in the Sent folder. You will have to change some of the code if you want it work in any other folder.
|
__________________
If you tell me how you get your feeling of importance, I'll tell you what you are.
|

02-24-2003, 12:41 PM
|
 |
Variable not defined
Retired Moderator * Guru *
|
|
Join Date: Apr 2002
Location: Ottawa, Ontario
Posts: 4,793
|
|
Hammering away works just fine.
However, you could use the Find and FindNext methods
This example is written as a to run from inside of Outlook. If you need to run it from outside of Outlook there are plenty of examples in the forum (or just look at Creeps post).
Code:
Sub FlagMessages()
Dim oMailitem As MailItem
Dim oMailItems As Items, i as Long
'All messages in current folder
Set oMailItems = Application.ActiveExplorer.CurrentFolder.Items
'Find first Unread message
Set oMailitem = oMailItems.Find("[To] = ""*All CFPSA HQ""")
'Loop through all unread messages
Do
'Count
i=i+1
'Find next message
Set oMailitem = oMailItems.FindNext
Loop Until oMailitem Is Nothing
'Number of messages
msgbox i
Set oMailitem = Nothing
Set oMailItems = Nothing
End Sub
Edit: added trailing VB tag 
|
__________________
-Carl
Last edited by Timbo; 02-25-2003 at 01:50 AM.
|

02-25-2003, 07:53 AM
|
|
Centurion
|
|
Join Date: Jan 2003
Posts: 190
|
|
|
thank you for your help. As a beginner in VB do I need to create this in my vb 6.0 studio starting with Standard exe then create project etc...?
And then I just make a command button to execute it?
Please advise.
|
|

02-25-2003, 08:52 AM
|
|
Newcomer
|
|
Join Date: Feb 2003
Location: Nor-Cal
Posts: 21
|
|
|
The easiest way to get this code working is just to open up Outlook, and then go Tools - Macro - VB Editor. You are going to need to insert a module and copy and paste this code in there then run it.
Use Wamphyri's code if you are going to be in Outlook exclusively, and use mine code if you are going to be outside of Outlook, and using it in a stand alone program, although, mine code will also work in Outlook.
I hope this helps.
|
__________________
If you tell me how you get your feeling of importance, I'll tell you what you are.
|

02-25-2003, 10:26 AM
|
|
Centurion
|
|
Join Date: Jan 2003
Posts: 190
|
|
|
Thanks it works great. I am trying to now add two more addresses. Is this correct?
Set oMailitem = oMailItems.Find("[To] = ""*All CFPSA HQ, **Second Address, **Third Address""")
|
|

02-25-2003, 10:53 AM
|
|
Newcomer
|
|
Join Date: Feb 2003
Location: Nor-Cal
Posts: 21
|
|
|
I do not think that would work, and unfortunately, there is a virus warning, so the IT team has disable the use of all macros in Outlook for the time being, so I can not test it. However, you could replace "*All CFPSHA HQ" with a string, and change the value of that string programmatically. Perhaps Wamphyri could back me up here, and give you a solid answer.
|
__________________
If you tell me how you get your feeling of importance, I'll tell you what you are.
|

02-25-2003, 11:03 AM
|
 |
Variable not defined
Retired Moderator * Guru *
|
|
Join Date: Apr 2002
Location: Ottawa, Ontario
Posts: 4,793
|
|
You need to use the OR condition.
Code:
Set oMailitem = oMailItems.Find("[To] = ""*All CPSA HQ"" OR [To] = ""*All CPR HQ""")
|
__________________
-Carl
|

02-25-2003, 11:54 AM
|
|
Centurion
|
|
Join Date: Jan 2003
Posts: 190
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|