ShowCategoriesDialog for multiple inbox items

P

PeterGates

I'm trying to set up a macro that opens the Categories dialog for items I
select from the Inbox (or other Outlook folder). Using the code below I can
assign categories for single mail items in turn (ie the dialog opens, I
select categories, they are applied to the first item and then the dialog
opens again for the next item).

Can anyone tell me a way to have the same cateories apply to the multiple
messages I select?

------
Sub ShowCategoriesDialog()
Dim OlExp As Outlook.Explorer
Dim OlSel As Outlook.Selection
Dim x As Integer

Set OlExp = Application.ActiveExplorer
Set OlSel = OlExp.Selection

For x = 1 To OlSel.Count
OlSel.item(x).ShowCategoriesDialog
Next x
End Sub
------
 
K

Ken Slovak - [MVP - Outlook]

Just call to open that dialog once, on the first selected item. Then pull
the categories from the item after the dialog closes and apply those
categories to the remainder of the selection. If you want you can get the
existing categories before you call to open the dialog to be able to compare
and see which were added/removed.
 
S

Sue Mosher [MVP]

I'd move the ShowCategoriesDialog statement so that it runs before the For
.... Next loop. Then use the loop to copy the Categories property value from
the first item to all the rest:

Set firstItem = OlSel.item(1)
firstItem.ShowCategoriesDialog
For x = 2 To OlSel.Count
OlSel.item(x).Categories = firstItem.Categories
Next x
 
P

PeterGates

Thanks for your help, it was quite a simple solution when I think about it.
It hasn't solved my problem though...

Now when I run the macro I get a dialog for the first item and the newly
added categories are shown (as coloured boxes) in the inbox window against
this first selected mail item only. The others don't appear to pick up a
category.

I added some msgbox lines in to display the categories inside the For-Next
loop and they return that the category is being assigned.

Any idea why this is?
Updated code:

-----
Sub ShowCategoriesDialog()
Dim OlExp As Outlook.Explorer
Dim OlSel As Outlook.Selection
Dim x As Integer

Set OlExp = Application.ActiveExplorer
Set OlSel = OlExp.Selection
Set FirstItem = OlSel.item(1)

FirstItem.ShowCategoriesDialog
MsgBox FirstItem.Categories, , "Item 1 Categories:"

For x = 2 To OlSel.Count
OlSel.item(x).Categories = FirstItem.Categories
MsgBox OlSel.item(x).Categories, , "Item " & x & " Categories:"
Next x
End Sub
 
P

PeterGates

Absolutely no apologies needed, you've helped an Outlook VBA novice out a
lot. I doubt this will be my last post - I have a few ideas I want to try and
implement...

Many thanks and best wishes.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top