Hello friends,
I am trying to create a custom search function for Outlook.
Background: our managers store project-related mails in singular psts in our file system, together with all other project material.
As they seldom only have one project at a time, they usually have several psts open in Outlook 2003.
Naturally, they sometimes have to search for specific mails and may not know in which project the issue had occured.
==>That is why I try to create a custom Outlook VBA search function, searching across all opened psts.
This is what I have so far:
As you can see, I create a folder in the inbox into which I copy all found mails. (Loved to simply list links to the mails in a grid, but don't know how to do that yet. Will be amended later)
It does cycle through the psts correctly, but the AdvancedSearch function always errors out with "one or more arguments invalid".
Do any of you know why and what I'm doing wrong?
Thanks a lot!
Andy
[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
I am trying to create a custom search function for Outlook.
Background: our managers store project-related mails in singular psts in our file system, together with all other project material.
As they seldom only have one project at a time, they usually have several psts open in Outlook 2003.
Naturally, they sometimes have to search for specific mails and may not know in which project the issue had occured.
==>That is why I try to create a custom Outlook VBA search function, searching across all opened psts.
This is what I have so far:
Code:
Dim pst As MAPIFolder, fol As MAPIFolder
Dim objSch As Search
Dim strF As String
Dim strS As String, i As Integer, j As Integer
Dim ns As Outlook.NameSpace
Dim inb As Object
Const strTag As String = "SubjectSearch"
On Error Resume Next
strF = "urn:schemas:mailheader:subject LIKE '%" & UserForm1.TextBox1.Text & "%'"
'Const strS As String = "Inbox"
Set ns = Outlook.GetNamespace("MAPI")
Set itm = ns.GetDefaultFolder(olFolderInbox)
Set fol = itm.Folders.Add("My global findings")
Debug.Print Outlook.Session.Folders.Count
For Each pst In Outlook.Session.Folders
j = j + 1
Set objSch = pst.Application.AdvancedSearch(Scope:=pst.Name, Filter:=strF, SearchSubFolders:=True, Tag:=strTag & j)
If objSch.Results.Count > 0 Then
For i = 1 To objSch.Results.Count
objSch.Results.Item(i).Copy fol.Name
Next i
End If
Next pst
As you can see, I create a folder in the inbox into which I copy all found mails. (Loved to simply list links to the mails in a grid, but don't know how to do that yet. Will be amended later)
It does cycle through the psts correctly, but the AdvancedSearch function always errors out with "one or more arguments invalid".
Do any of you know why and what I'm doing wrong?
Thanks a lot!
Andy
[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell