VBA: how to set a category to all mail in a folder ?

  • Thread starter Thread starter notme
  • Start date Start date
N

notme

Hi everyone,
I need to set automatically a category to alll email in a IMAP folder. (and
for every new incoming email in this folder)
I've found this code in VBA but it give a category only to the selected
email when the macro is launch.

Sub essai()

Dim MonApply As Outlook.Application
Dim Expl As Explorer
Dim myNameSpace As NameSpace
Dim myFolder As MAPIFolder
Dim myItems As Items
Dim xi As Integer

'object instance
Set MonApply = Outlook.Application 'Application Outlook

'Expl is current folder
Set Expl = ActiveExplorer
'give you all datas embedded
Set myNameSpace = MonApply.GetNamespace("MAPI")

'retreive ID folder to get all messages
Set myFolder =
myNameSpace.GetFolderFromID(Expl.CurrentFolder.EntryID)

'myItems is all items in this folder
Set myItems = myFolder.Items

For xi = 1 To myItems.Count
'this loop should give a category named as the folder name to all
items in folder
myItems.Item(xi).Categories = myFolder.Name

Next xi

End Sub
 
See the ItemAdd event. An example is available in the VBA help file.

--
Best regards
Michael Bauer - MVP Outlook
Category Manager - Manage and share your categories:
SAM - The Sending Account Manager:
<http://www.vboffice.net/product.html?lang=en>


Am Thu, 13 May 2010 10:26:32 +0200 schrieb notme:
 
Back
Top