ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA - AHK script - Outlook'03 Apply Category Label

(1/7) > >>

wideeyedguy:
Would like to use AHK script to assign a Category label called "1 - Client - sent to"
to an email that is open and/or to one that is merely selected (but not open) in an email folder.

Is this doable? Can you give me some guidance?


Thank you,
weg

r0bertdenir0:
Yes it's doable.
But I think AHK is the second choice in this case - but that's just going on yr post.
If you do this with AHK you'd basically be simulating user interaction & filling in the relevant dialogs.
That's fine but Office apps are notorious for undocumented features & the 1st I noticed was Outlook seemed to hang when I first entered a new Category & then worked fine. :tellme:

In any case, I think a better way for you to go is to use VBA in Outlook.
It's a simple matter to write a macro that will write the data to the Categories field of a MailItem.
Then create a custom toolbar & a button linked to the macro. Whenever you need to, just click the button & yr category is set!
You can even put a loop in the macro so that you can select multiple items & set the Category for all items at once.

It's actually just half a page of code so I'll post it for you in a little bit.

r0bertdenir0:
Ok, this is what I came up with - hope it's what you're looking for.
Open the VBA editor in Outlook (Alt F11), click the Insert menu & click Module & paste this code into the new module.
Then open the Immediate window (Ctrl G), type AddCustomCategoriesToolbar & hit Enter.

(You can also open the ThisOutlookSession object & run AddCustomCategoriesToolbar from the Application_Startup event.)

One more thing, you'll see the category added but in brackets the note (not in Master Category List)
The category is still associated with the email.
Outlook 2003 doesn't give programmatic access to the Master Category List, so if you wanna get rid of that side-note, add it yrself via the Categories dialog & you won't have any problems.
But as far as I can make out it's just cosmetic.


--- Code: Visual Basic ---Option Explicit Private Const MY_CUSTOM_TOOLBAR__ = "Virtua"Private Const MY_CUSTOM_CATEGORIES_BUTTON__ = "Set Categories"Private Const MY_CUSTOM_CATEGORIES__ = "1 - Client - sent to"  Public Sub AddCustomCategoriesToolbar()On Error Resume NextDim oNewCmdBar As CommandBarDim oNewButton As CommandBarButton        '**first check if toolbar exists    Set oNewCmdBar = Application.ActiveExplorer.CommandBars.Item(MY_CUSTOM_TOOLBAR__)    '**otherwise create it    If (oNewCmdBar Is Nothing) Then        Set oNewCmdBar = Application.ActiveExplorer.CommandBars.Add(MY_CUSTOM_TOOLBAR__)    End If        '**first check if button exists    Set oNewButton = oNewCmdBar.Controls.Item(MY_CUSTOM_CATEGORIES_BUTTON__)    '**otherwise create it    If (oNewButton Is Nothing) Then        Set oNewButton = oNewCmdBar.Controls.Add(msoControlButton)    End If    '**set the caption & macro to run    oNewButton.Caption = MY_CUSTOM_CATEGORIES_BUTTON__    oNewButton.OnAction = "CustomActions_Categories"        '**by default they are created invisible    oNewButton.Visible = True    oNewCmdBar.Visible = True    End Sub  Private Sub CustomActions_Categories()On Error Resume NextDim oItem As ObjectDim oNewCmdBar As CommandBarDim oNewButton As CommandBarButton     Set oNewCmdBar = Application.ActiveExplorer.CommandBars.Item(MY_CUSTOM_TOOLBAR__)    Set oNewButton = oNewCmdBar.Controls.Item(MY_CUSTOM_CATEGORIES_BUTTON__)        oNewButton.Caption = "Working..."    DoEvents        '**loop thru selected items    For Each oItem In ActiveExplorer.Selection        '**set their categories if they have the property        oItem.Categories = MY_CUSTOM_CATEGORIES__        '**save our change        If (Err = 0) Then            oItem.Save        End If            Next oItem     oNewButton.Caption = MY_CUSTOM_CATEGORIES_BUTTON__ End Sub

wideeyedguy:
r0bertdenir0 - Thank so much for taking the time to reply and work this up.

What is the trick to copying the code and having the line breaks correct?
When I paste, it's essentially all on one line.

weg

mouser:
i dont get the all-on-one-line problem, BUT i also have trouble copying and pasting the code in the highlighter box.. let me see if there is some way to fix that..

Navigation

[0] Message Index

[#] Next page

Go to full version