Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    861
    Thanks
    0
    Thanked 10 Times in 9 Posts

    Outlook message tag using VBA

    We want to offer our users the ability to add "Confidential" to the beginning of the subject line of an Outlook mail message.

    Code:
    Sub InsertBeforeSubjectLine()
        Dim olkMsg As Outlook.mailItem
        Set olkMsg = Outlook.Application.ActiveInspector.CurrentItem
        'olkMsg.Save
        olkMsg.Subject = "CONFIDENTIAL " & olkMsg.Subject    
    End Sub
    The above code functions well if the user has tabbed out of the Subjet field after typing their subject text. That action (tabbing out of the Subject field) gives the mail item a name, and VBA is able to read the current subject line. If the user hast NOT tabbed out of the Subject field, CONFIDENTIAL replaces the subject line text instead of being prefixed to it.

    olkMsg.Save, which I've commented out above, resolves the issue, except for one thing: if the user Cancels the message (Sytem Control, "X" at upper right of window) the saved message remains in the Drafts folder. (Sending the message deletes the item from the Drafts folder.)

    Is there a way to get the subject line without saving the message, and thus risking having the message remain in the Drafts folder for the user to deal with at a later time?

    Thanks.

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,371
    Thanks
    206
    Thanked 827 Times in 760 Posts
    Richard,

    How is your Macro fired, e.g. what triggers it? You might want to look at triggering it via an Outlook event such as Save or ItemSend, etc. You could then include a prompt in the code to ask the user whether or not to include the prefix in the subject. HTH
    Last edited by RetiredGeek; 2013-10-07 at 20:27.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    861
    Thanks
    0
    Thanked 10 Times in 9 Posts
    It's triggered from an icon on the Ribbon; the user clicks at will. We are moving to Outlook from another email client. This is a feature that we had previously, and the functionality must remain the same.

    It looks like Outlook VBA reads the title of the window as the subject, and until the window title is updated by pressing Enter or Tab in the subject field, the window title remains "Untitled" or whatever it was prior to modifying the subject line. I understand the logic, but it doesn't work for us.

Posting Permissions

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