Search code examples
vbaemailoutlookoutlook-2010

How can I rename the subject of one (or more) mail in one click?


French laws say that you can use your professional mail account to send private mails.

But if you want to keep the privacy of this mail, its subject has to contain a mention about this privacy (with the word "Perso" or "Privé", for instance).

The problem is when you received mails from other people, you have to rename them manually.

How to add a button to do it in one click in Outlook?


Solution

  • With Outlook, you can create your own script. Here is how to do it.

    1. Activation of the developer tab in the ribbon

    1. Click on the file tab
    2. Click on "Options"
    3. Choose "Customize Ribbon"
    4. On the right of the window, tick "Developer"

    2. Creation of the script

    1. Click on the developer tab and choose "Macros" (twice)
    2. Give a name to your new macro ("renamePerso" for instance) and click on "Create"
    3. In the new window, you have to enter the code who will be executed.

    Copy and paste this code :

    Sub renamePerso()
        For x = 1 To Outlook.Application.ActiveExplorer.Selection.Count
            Set obj = Outlook.Application.ActiveExplorer.Selection.Item(x)
            If obj.Class = OlObjectClass.olMail Then
                obj.Subject = "[PERSO] " + obj.Subject
            End If
        Next x
    End Sub
    
    1. You can now quit the editor, your code must be save

    3. Give a quick access to your macro

    1. Click on the file tab
    2. Click on "Options"
    3. Choose Quick Access Toolbar
    4. Under "Choose commands from:", select "Macros"
    5. Select your macro and click on "Add > >"
    6. Under the list of commands, tick "Show Quick Access Toolbar below the Ribbon"

    4. How to use the script

    To add the "[Perso]" mention at the beginning of the subject of an email (or a couple), you just have to :

    • select it (or them with either Ctrl or Shift)
    • click on the corresponding button under the Ribbon

    If, after your reboot, you can't use your macro again, you have to check your security settings.