A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

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



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 13th 10, 10:26 AM posted to microsoft.public.outlook.program_vba
notme
external usenet poster
 
Posts: 2
Default VBA: how to set a category to all mail in a folder ?

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.Ent ryID)

'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

Ads
  #2  
Old May 13th 10, 12:09 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default VBA: how to set a category to all mail in a folder ?



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:

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.Ent ryID)

'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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Move email messages to a specified folder based on a category DougLost Outlook and VBA 2 October 7th 10 04:18 PM
VBA: set a category to all mail in a folder notme Outlook - General Queries 1 April 29th 10 04:38 PM
Category Colours not showing in Public folder calendar John McGregor Outlook - Calandaring 1 December 8th 09 09:06 PM
Sending emails by category, and folder with Outlook 2007 Steve Outlook - Using Contacts 2 February 1st 09 10:16 PM
Copy centain contacts to new folder based on category Bob Day Outlook - Using Contacts 0 July 24th 06 10:41 PM


All times are GMT +1. The time now is 09:06 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.