• Outlook message tag using VBA

    Author
    Topic
    #491322

    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.

    Viewing 1 reply thread
    Author
    Replies
    • #1415682

      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 :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1415686

      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.

    Viewing 1 reply thread
    Reply To: Outlook message tag using VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: