PDA

View Full Version : Using ShowCategoriesDialog



ibex
09-03-2010, 10:56 PM
Firstly I'm not a VBA programmer so this may be really obvious but I can't find the answer myself.
I have a very simple macro in Outlook 2007 that is called when the "send" button is pressed

Private Sub Application_ItemSend(...
This macro brings up the ShowCategoriesDialog so that I can assign a category (1 or more) to each outgoing email. This works fine.

' Pick the category
Set item = Outlook.Application.ActiveExplorer.Selection.item(1)
item.ShowCategoriesDialog

What I would like to do is take different actions depending on whether the "OK" or the "Cancel" button is clicked to exit the ShowCategoriesDialog. I don't know how to detect which button was presssed or even know if the button result is available once the ShowCatagoriesDialog has returned.

All help gratefully accepted.

Crocus Crow
09-04-2010, 04:25 PM
I don't think Outlook can tell you whether the OK or Cancel button was clicked, but it does return the result of the dialogue in Item.Categories, which is a comma-separated string of selected Categories. Therefore you could do this:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim currentCategories As String

currentCategories = Item.categories
Item.ShowCategoriesDialog
If Item.categories = currentCategories Then
MsgBox "Cancel clicked, or OK clicked and no different categories selected: " & Item.categories
Else
MsgBox "OK clicked and these categories selected: " & Item.categories
End If

End Sub

ibex
09-04-2010, 09:14 PM
OK thanks - I can use that, just not as clean as I'd like.