Results 1 to 4 of 4

Thread: VB help (OL2K)

  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB help (OL2K)

    Is there an Outlook VB literate person out there, please?
    I would like a macro (which will attached to a toolbar button) that adds a specified category to a mail reply. The purpose is to ensure a reply to an incoming mail can be forced to have the defined category assigned to it so a rule can intercept the outgoing reply and make another copy.
    (This can of course be done from within the Reply by clicking on Options and setting the category there, but the request was 'please can we have a button to click which will set this category')
    I'm a complete VB illiterate, I'm afraid, and I don't know if this forum is the right place or whether it should be posted on the VB site.
    TIA
    Silverback

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VB help (OL2K)

    Try this:
    <pre>Sub SetCategory()
    Dim itmMessage As MailItem, strFingerprint As String
    'if macro is run in the wrong context, there will be an error
    On Error Resume Next
    Set itmMessage = ActiveInspector.CurrentItem
    If Err <> 0 Then
    MsgBox "Please create a new mail message and then try again. [" & _
    Err.Description & "]"
    Exit Sub
    End If
    On Error GoTo 0

    'set category field
    strFingerprint = <font color=red>"Gotcha!"</font color=red>
    If InStr(1, itmMessage.Categories, strFingerprint, vbTextCompare) = 0 Then
    'category does not already exist in the message, add to the end of the categories list
    itmMessage.Categories = itmMessage.Categories & _
    IIf(Len(itmMessage.Categories) > 0, ", ", vbNullString) & _
    strFingerprint
    End If
    Set itmMessage = Nothing
    End Sub</pre>

    You will need to set the "Gotcha!" text to the category you really want.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB help (OL2K)

    Jefferson, you are the best. <img src=/S/bow.gif border=0 alt=bow width=15 height=15> <img src=/S/clever.gif border=0 alt=clever width=15 height=15>

    Thanks very much. It works perfectly - but I would like to know how one gets to be so skilled in VB
    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Silverback

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VB help (OL2K)

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15> I learned WordBasic and VBA by being absurdly curious, and stubborn, dissecting code that worked, and making lots of mistakes. And doing it regularly ('cause it's easy to forget things). I also buy way too many books, many of which are not that useful. I bet there are better ways. <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •