views:

141

answers:

1

Hi,

I am trying to transform my Outlook2003 into the closest thing to gmail.

I started to use categories, which are pretty similar to labels in gmail. I can assign categories automatically with rules, and I can add categories manually. I have also created "search folders", that show all mails with a given category, if they are not in the Deleted Items or Sent Items folders. This part is almost like the Label views in gmail.

Two things are missing basically, which should be done with macros (VBA to be precise) which I'm totally inexperienced with. So hence my questions:

-Can someone show me a macro to remove the category "Inbox"? That would act exactly like the Archive button in gmail. In fact I want to assign this macro to a toolbar button and call it Archive. I have a rule that adds the Inbox category to all incoming mail. As I said, I have a search folder displaying all mails categorized as Inbox, and I also have an All Mail search folder, that displays all messages regardless whether they have the Inbox category. Exactly like gmail, just the easy archiving is missing.

-Can someone show me a macro that would delete the selected mail/mails and also would remove the Inbox category before deletion? I would replace the default delete button with this macro. (Somewhat less important, as in my search folders I can filter messages that are physically placed in the Deleted Items folder, but it would be more elegant not to have mails categorized as Inbox in the trash.

Many thanks in advance,

szekelya

A: 

Hi szekelya, I have used Sue's remove code from http://www.outlookcode.com/codedetail.aspx?id=1211

But this should work you

Added save ! Doh!

Sub UnAssignInboxCat()
Dim SelectedItems As Selection
Dim Item As MailItem


Set SelectedItems = Application.ActiveExplorer.Selection

For Each Item In SelectedItems

RemoveCat Item, "Inbox"
Item.Save
Next

Set SelectedItems = Nothing
Set Item = Nothing

End Sub
Sub DeleteAndUnAssignInboxCat()
Dim SelectedItems As Selection
Dim Item As MailItem
Set SelectedItems = Application.ActiveExplorer.Selection

For i = SelectedItems.Count To 1 Step -1
    Set Item = SelectedItems.Item(i)
    RemoveCat Item, "Inbox"
    Item.Save

    Item.Delete
Next

Set SelectedItems = Nothing
Set Item = Nothing

End Sub




Sub RemoveCat(itm, catName)
    arr = Split(itm.Categories, ",")
    If UBound(arr) >= 0 Then
        ' item has categories
        For i = 0 To UBound(arr)
            If Trim(arr(i)) = catName Then
                ' category already exists on item
                ' remove it
                arr(i) = ""
                'rebuild category list from array
                itm.Categories = Join(arr, ",")
                Exit Sub
            End If
        Next
    End If
End Sub
76mel
Hi 76mel,thanks a lot!It's almost perfect. Sub UnAssignInboxCat() removes the Inbox category as expected however outlook needs select the next message to remove it from the current view (search folder displaying messages with category Inbox).Could you add a command to select the next message, so that the category removal could result in disappearing from that search folder?Sub DeleteAndUnAssignInboxCat() deletes the message, but somehow the categories are not removed.Many thanks,szekelya
szekelya
Sorry I didnt add the Save .. Have now
76mel
76mel, I'm speechless. This is brilliant, thank you very much! My outlook 2003 became a modern, productive taggable mail client.Thank you very much.szekelya
szekelya
My pleasure helping you out.
76mel