VBA script for counting emails by a certain sender

Redlad1291

New Member
Joined
Nov 2, 2016
Messages
13
Hi I currently have a VBA script set up to count how many emails are in a mailbox but would like it to count from a certain sender in that mailbox.

curntly my script is set up with the following;

set objfolder = objnspace.folders("mailbox").folders("inbox")

does anyone know what I can add to this so it only counts it from a certain email address?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You can loop through a folder and and each item in the folder has a SenderName property if it is an email. While looping through the folder you can count how many of the emails are from a particular email address. For example:

Code:
set objfolder = objnspace.folders("mailbox").folders("inbox")

Dim MickeyCount as Integer

MickeyCount = 0

For Each objItem in objFolder
    If objItem.SenderName = "Mickey.Mouse@Disney.Com" then MickeyCount = MickeyCount + 1
Next
 
Upvote 0
Here's another way...

Code:
objfolder.Items.Restrict("[SenderEmailAddress] = 'john@xyz.com'").Count
 
Upvote 0
Thanks they both worked, do you know if it's possible to get a screenshot of a calendar in outlook through VBA aswell and paste over a certain amount of cells in excel?
 
Upvote 0
The only way I know of to grab a screen shot would require Outlook to be open, then you would have to do API calls to capture the screen to the clipboard, then copy it to a shape which would be placed on the worksheet. That wouldn't be very much fun to code.

An alternative would be to access the calendar data in Outlook and place the contents in cells on the worksheet, then format the cells such that it looks like a calendar.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,127
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top