The steps are the same for all versions of Outlook and all Office applications
It's easy to find code samples on the Internet, but unless you know how to use them, they aren’t going to do you much good.
We're going to assume the code is 100% ready-to-use, not a code snippet that is half complete.
If the code will be run against items in your mailbox or personal folders, you should make a backup of the mailbox or data file, just in case something goes wrong with the code. If the code runs against a specific folder, copying the folder and contents may be enough "insurance", (You should have routine backups regardless, but I know many users don't bother.) At least very least, make a copy of the items in the folder you are running the code against.
Check Macro Security Level
Outlook 2007 and older: Access the dialog to change the security level from Tools, Macros, Security.
Outlook 2010: File, Options, Trust Center, Macros.
Set the macro security to "always ask". Do not choose the Low option (run all, never ask). Some security software will set it to High and your macros will not run. You may need to restart Outlook after changing the security setting.
Open the VBA Editor
Now you are ready to open the VBA Editor. You can either press Alt+F11 on your keyboard or use the Tools, Macros, Visual Basic Editor command to open it.
If your screen does not resemble the screenshot on the right, with the white editing pane open, you'll need to click on Microsoft Outlook Objects to expand it then double click on ThisOutlookSession to open it in the editing pane on the right side.
Now all that's left is to paste (or type) the code into the ThisOutlookSession window.
Where to paste the VBA code
Generally speaking, you can put the code into either ThisOutlookSession or a Module, unless otherwise noted that it must be in ThisOutlookSession or a module.
Application_Start macros must be in ThisOutlookSession.
This macro was recorded in Outlook 2013, however, the VBA editor has not changed in any version.
Run the Macro
Press F5 or the Run button to run the macro from the VBA editor. (It's highly recommended you make a backup of the folders or message store before running macros.)
Ctrl+Break will pause the macro, or press the Stop button on the toolbar to end it.
If you will be using the macro often, you might want to use selfcert to sign it then set Macro security to only run signed macros. Note that you don't want to sign the macro until you are done tweaking it and if you tweak it later, you'll need to resign it.
To run the macro from Outlook 2007 or older, go to Tools, Macro, Macros and select the macro. In Outlook 2010, you need to show the Developer ribbon first (File, Options, Customize Ribbon – check Developer ribbon on the right). You can also open the Macros dialog using Alt+F8 (all versions). You can also add macros to toolbar or ribbon buttons.
To sign a macro using selfcert, you first need to create a certificate. You can find selfcert in the folder with your Office files, usually at
C:\Program Files\Microsoft Office\OfficeXX
where XX is your version of Office. If you use 64-bit Windows and 32-bit Outlook, it's in the 32-bit Programs directory.
It's simple to use: just type a name for your digital certificate then click ok.
Once you have the certificate, sign the macros using Tools, Digital Signature dialog and choosing a certificate.
Note that every time you edit the macro you'll need to resign it.
How to use Selfcert.exe Video Tutorial
If you are going to be using a macro often, you will probably want to create a toolbar button for it.
In Outlook 2007 (main interface) and older: right click on the toolbar area and choose Customize. Switch to the Commands tab and find Macros on the left. Drag the macro from the right side to the toolbar and drop. Right click on it to edit the name and button image.
In Outlook 2007 ribbon: you can only add buttons to the QAT. Right click on a ribbon tab and choose Customize Quick Access Toolbar. Select Macros from the Choose commands from menu then select the macro and Add it to the right pane. (When you add buttons to the QAT you can use Alt+n keyboard shortcuts.)
In Outlook 2010 you can add buttons to the QAT or the ribbon. Go to File, Options and choose Customize Ribbon or Quick Access Toolbar. Select Macros from the Choose commands from menu then select the macro and Add it to the right pane.