![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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)? |
Ads |
#2
|
|||
|
|||
![]()
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" |
#3
|
|||
|
|||
![]() 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". |
#4
|
|||
|
|||
![]()
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". |
#5
|
|||
|
|||
![]() 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? |
#6
|
|||
|
|||
![]()
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? |
#7
|
|||
|
|||
![]()
Ah, it all works now. That's fantastic, Ken - just what I wanted.
Thanks for your help. |
#8
|
|||
|
|||
![]() ..... and thanks to Michael too, of course, who I just realised supplied the original macro! |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook Should Count Invitees | Oscar Trevino | Outlook - Calandaring | 0 | June 20th 06 07:33 PM |
Email count mismatched | Peretz Stern | Outlook - General Queries | 0 | June 12th 06 06:33 PM |
Recurring Days That Count Up | Ron Anthony Quinn | Outlook - Calandaring | 0 | May 10th 06 07:37 PM |
How can I count how many contacts I have ? | How can I count how many contacts I have | Outlook - Using Contacts | 1 | May 4th 06 10:24 PM |
count contacts | ems@drg | Outlook - Using Contacts | 1 | February 23rd 06 06:54 PM |