Last reviewed on July 23, 2013   —  No Comments

Applies to Microsoft Outlook 2013, Outlook 2010, Outlook 2007

It's not hard to image this scenario: you create a custom view, everything is just the way you like it. Then you accidentally sort by a different column. Outlook saves the changes and your perfect view is ruined.

In the early versions of Outlook, users were presented with a "Do you want to save changes?" dialog, however, this dialog was confusing and annoying. Later versions saved changes to view automatically and the scenario above was all too common.

You can use a VBA macro to prevent changes from being saved – you can still sort the columns and change the view, but when you leave the folder and return, the original layout of the custom view is restored.

This VBA sample code will prevent changes from being saved to the views. You can use an If statement to lock only views available to Everyone, or lock all views. If you need to make a change to the view, you'll need to unlock it by changing Call LockView(objView, True) to Call LockView(objView, False).

The macro as, written, locks the view on the default Inbox: Set objViews = objName.GetDefaultFolder(olFolderInbox).Views. You'll need to change the folder to apply it to other folders.

After adding the view to the VBA Editor, click in it then click Run or press F8 key. This will lock the views. You do not need to add a button to the ribbon or toolbar or run it frequently. However, if you need to edit a view, you'll need to unlock the views (by changing True to False) to make the changes then re-lock it.

Sub LocksPublicViews()
 'Locks the interface of all views that are available to
 'all users of this folder.
 Dim objName As Outlook.NameSpace
 Dim objViews As Outlook.Views
 Dim objView As Outlook.View
 Set objName = Application.GetNamespace("MAPI")
 Set objViews = objName.GetDefaultFolder(olFolderInbox).Views
 For Each objView In objViews
 If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then
   Call LockView(objView, True) ' False = unlock
 End If
 Next objView
End Sub
Sub LockView(ByRef objView As View, ByVal blnAns As Boolean)

 With objView
 If blnAns = True Then
 'if true lock UI
  .LockUserChanges = True
 'if false don't lock UI
  .LockUserChanges = False
 End If
 End With
End Sub

The line If objView.SaveOption = olViewSaveOptionThisFolderEveryone Then determines which views are locked. In this example, only the views created for This Folder are locked. This can be changed to lock views available in all folders (of the item type) or lock private views.

Name Manage Views New Views Description
olViewSaveOptionThisFolderEveryone This folder This folder, visible to everyone
olViewSaveOptionThisFolderOnlyMe This folder (Private) This folder, visible only to me
olViewSaveOptionAllFoldersOfType All [item type] folders All [item type] folders

Manage views shows who can use the view

To lock the view in the current folder, replace Set objViews = objName.GetDefaultFolder(olFolderInbox).Views with Set objViews = Application.ActiveExplorer.CurrentFolder.Views

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Leave a Reply

Please post long or more complicated questions at OutlookForums by

If the Post Comment button disappears, press your Tab key.