Feb 4th, 2005, 12:53 AM
#1
Programmatically Create an Outlook Search Folder
This code will create a search folder in Outlook 2003+. Its convienent when you frequently run the
same search over and over again.
The search folder contents (if any hits are returned) are not actually in the folder but is just a query view result
listing. So if you were to delete the search folder you will not be deleting the contents. But if you view a particular
found item and delete it, then you will be deleting the actual item.
The SCOPE is newly added to 2003 but is originally from Exchange Server.
Enjoy and please post any comments or features you would like to see.
VB Code:
Option Explicit
'Add reference to MS Outlook 11.0 Object Library
Private Sub Command1_Click()
Dim oApp As Outlook.Application
Dim oSearch As Outlook.Search
Dim oInbox As Outlook.MAPIFolder
Dim oSearchFolder As Outlook.MAPIFolder
Dim sFolderPath As String
Dim sScope As String
Dim sFilter As String
On Error Resume Next
Set oApp = New Outlook.Application
Set oInbox = oApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
sFolderPath = oInbox.FolderPath
'Build a scope string
sScope = "SCOPE ('shallow traversal of " & Chr$(34) & sFolderPath & Chr$(34) & "')"
'Build a filter string (WHERE clause without the WHERE)
sFilter = Chr$(34) & ("urn:schemas:mailheader:subject") & Chr$(34) & " LIKE 'RE:%'"
'Create the Search object by calling AdvancedFind
Set oSearch = oApp.AdvancedSearch(sScope, sFilter, False, "RE Search")
'Save the Search as a Search Folder
Set oSearchFolder = oSearch.Save("RE Search")
MsgBox oSearchFolder.Items.Count & " Items found!"
'oSearchFolder.Delete
End Sub
VB/Outlook Guru™
Attached Images
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
May 14th, 2007, 01:05 PM
#2
New Member
Re: Programmatically Create an Outlook Search Folder
Hey Rob,
How can i delete the search folder programmatically???
Is it possible?
I was not able to find any answer to this
Thanks
-SpYeYeS
Jul 29th, 2007, 06:23 PM
#3
Re: Programmatically Create an Outlook Search Folder
Its possible (user created) as its nothing more then a mapifolder object with a filter on it.
Just create an object variable of mapifolder type and set it to the search folder desired to be deleted and .Delete it.
Code:
Dim oDelSearch As Outlook.MAPIFolder
Set oDelSearch = oApp.GetNamespace("MAPI").Folders("Your Search Folder Name")
oDelSearch.Delete
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Aug 18th, 2011, 09:35 PM
#4
Lively Member
Re: Programmatically Create an Outlook Search Folder
Last edited by savior14; Aug 18th, 2011 at 09:37 PM .
Reason: posted in wrong thread while using this page as a reference
im a newbie in vb.net field so please always bear with me
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width