Exporting outlook data from shared mailbox - date range

0987

New Member
Joined
Mar 1, 2021
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
Hi. I have found how to export data from a shared mailbox in outlook from a previous post using the below code. This works fine but I want to be able to extract the data between two specified dates that might change (between 04 Feb and 13 Feb for example). Is there a way to do this rather than just bringing back today’s date as works with this code? Thank you very much.


Option Explicit
Public Sub ReadOutlookEmails()
Dim objFolder As Outlook.Folder
Dim objNamespace As Outlook.Namespace
Dim objMail As Outlook.MailItem
Dim lngCounter As Long
Set objNamespace = Outlook.GetNamespace("MAPI")
Set objFolder = objNamespace.PickFolder
If TypeName(objFolder) = "Nothing" Then
Exit Sub

End If
Dim varItems As Variant

Set varItems = objFolder.Items.Restrict("[Received] >= '" & Format(Split(Now(), " ")(0) & " 12:00am", "ddddd h:nn AMPM") & "'") ' Today
For lngCounter = 1 To varItems.Count
Set objMail = varItems(lngCounter)

shMailReport.Range("A" & lngCounter + 1).Value = objMail.SenderName
shMailReport.Range("B" & lngCounter + 1).Value = objMail.Subject
shMailReport.Range("C" & lngCounter + 1).Value = objMail.Size
shMailReport.Range("D" & lngCounter + 1).Value = objMail.ReceivedTime
shMailReport.Range("E" & lngCounter + 1).Value = objMail.Categories
Next
MsgBox "Finished", vbInformation

End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

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