![]() |
Count dates
I have Outllok 2003 running on an Exchange server. I don't normally
program VBA in Outlook, only Word or Excel. Is there a way I could do a little macro to count the messages in a folder and produce a list of how many messages are present for each date (like 26 for Aug 10, 33 for Aug 9, 12 for Aug 8, etc)? |
Count dates
On 10 Aug 2006 01:09:36 -0700, stevewy@... wrote in
microsoft.public.outlook.program_vba: I have Outllok 2003 running on an Exchange server. I hope you don't mean that. Outlook running on the Exchange Server is not a good thing. I don't normally program VBA in Outlook, only Word or Excel. The techique below is not very Outlook-specific. Is there a way I could do a little macro to count the messages in a folder and produce a list of how many messages are present for each date (like 26 for Aug 10, 33 for Aug 9, 12 for Aug 8, etc)? VBA's Dictionary Object springs to mind as an appropriate tool. Here's some code that should get you started: Sub CounDates() Dim fldFolder As MAPIFolder Dim dctDict As New Scripting.Dictionary Dim itmMail As MailItem Dim strDate As String Dim itmNote As NoteItem Dim i As Long Set fldFolder = ActiveExplorer.CurrentFolder Set dctDict = CreateObject("Scripting.Dictionary") ' This will fail if there are items other than MailItems in the folder For Each itmMail In fldFolder.Items strDate = Format(itmMail.ReceivedTime, "YYYY-MMM-DD") dctDict.Item(strDate) = dctDict.Item(strDate) + 1 Next itmMail ' Saving the results in a NoteItem Set itmNote = CreateItem(olNoteItem) itmNote.Body = "Counted " & fldFolder.Items.Count & " mail items for " _ & dctDict.Count & " dates in folder """ & fldFolder.Name & """:" & vbCr For i = 0 To dctDict.Count - 1 itmNote.Body = vbCr & itmNote.Body & dctDict.Keys(i) & ": " & dctDict.Items(i) & vbCr Next i MsgBox "Counted " & fldFolder.Items.Count & " mail items for " _ & dctDict.Count & " dates in folder """ & fldFolder.Name & """.", vbOKOnly + vbInformation, "CountDates" itmNote.Display End Sub -- Michael Bednarek http://mbednarek.com/ "POST NO BILLS" |
Count dates
I'm getting an error when I run it. The error comes on the line "Dim dctDict As New Scripting.Dictionary" and says "Compile error: user defined type not defined". |
Count dates
Put a reference to the Scripting object in your VBA project references.
And never, ever run Outlook on the Exchange server, it's a bad idea. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm wrote in message oups.com... I'm getting an error when I run it. The error comes on the line "Dim dctDict As New Scripting.Dictionary" and says "Compile error: user defined type not defined". |
Count dates
Ken Slovak - [MVP - Outlook] wrote: Put a reference to the Scripting object in your VBA project references. And never, ever run Outlook on the Exchange server, it's a bad idea. Well, I don't actually know that it's running *on* the server. I think maybe the e-mail accounts are stored on there. I leave that to the techies. Err... how do I put a reference to the Scripting object in your VBA project references exactly? |
Count dates
Tools, References.
Set the reference to Microsoft Scripting Runtime (SCRRUN.DLL). -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm wrote in message ups.com... Ken Slovak - [MVP - Outlook] wrote: Put a reference to the Scripting object in your VBA project references. And never, ever run Outlook on the Exchange server, it's a bad idea. Well, I don't actually know that it's running *on* the server. I think maybe the e-mail accounts are stored on there. I leave that to the techies. Err... how do I put a reference to the Scripting object in your VBA project references exactly? |
Count dates
Ah, it all works now. That's fantastic, Ken - just what I wanted.
Thanks for your help. |
Count dates
..... and thanks to Michael too, of course, who I just realised supplied the original macro! |
All times are GMT +1. The time now is 06:59 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com