-1

I would like to ask if anyone has a ready snippet or can provide a working one which would do the below:

VBA or powershell script to extract email details (sender,recipient,subject,time stamp) from sent items and all its subfolders based on a date range

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Bobby
  • 1
  • 1
  • braX I am using the one from this threat and tried to manipulate it to do as I wanted but since I am not very much into this I could not and posted the question here https://www.vishalon.net/blog/export-outlook-from-to-subject-receive-date-and-other-meta-data-into-excel – Bobby Dec 23 '21 at 12:56
  • 1
    You will have a much better experience in this Q & A site if you provide your research. As well keep in mind many if not all Outlook VBA questions have been asked before. Break your post into smaller parts and search the site if you have no code. – niton Dec 30 '21 at 17:24

1 Answers1

0

The Outlook object model is common for all programming languages, so I hope you will be able to apply the following explanation to a PS script.

There are several ways to get the job done it right in Outlook.

  1. Use the Find/FindNext or Restrict method of the Items class to get the items collection that correspond to your search criteria and then iterate over all of them. Read more about these methods in the following articles:
  1. Use the Table.Restrict method which applies a filter to the rows in the Table and obtains a new Table object. The Filter parameter is a query on specified properties of items that are represented as rows in the parent Table. The query uses either the Microsoft Jet syntax or the DAV Searching and Locating (DASL) syntax. For example, the following Jet filter and DASL filter specify the same criteria for items with ReceivedTime earlier than 3:30pm of December 12, 2021:
criteria = "[ReceivedTime] < '" & Format$("12/12/2021 3:30PM","General Date") & "'"

For example:

Sub RestrictTable() 
 'Declarations 
 Dim Filter As String 
 Dim oRow As Outlook.Row 
 Dim oTable As Outlook.Table 
 Dim oFolder As Outlook.Folder 
 
 'Get a Folder object for the Inbox 
 Set oFolder = Application.Session.GetDefaultFolder(olFolderSentItems) 
 
 'Define Filter to obtain items last modified after November 1, 2005 
 Filter = "[ReceivedTime] > '12/12/2021'" 
 'Restrict with Filter 
 Set oTable = oFolder.GetTable(Filter) 
 
 'Enumerate the table using test for EndOfTable 
 Do Until (oTable.EndOfTable) 
 Set oRow = oTable.GetNextRow() 
 Debug.Print (oRow("EntryID")) 
 Debug.Print (oRow("Subject")) 
 Debug.Print (oRow("CreationTime")) 
 Debug.Print (oRow("LastModificationTime")) 
 Debug.Print (oRow("MessageClass")) 
 Loop 
End Sub
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45