• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Apply a View to a Folder using a Macro

Slipstick Systems

› Developer › Apply a View to a Folder using a Macro

Last reviewed on December 4, 2018     15 Comments

Applies to: Outlook (classic), Outlook 2007, Outlook 2010

In the thread at OL10 add views to 'my tasks'> navigation pane, users are disappointed the list of views was removed from the Navigation pane in Outlook 2010. While this macro won't add the views list back, it can make it easier to switch between your favorite views.

You'll need to create one macro and one button on the QAT or ribbon for each view you want to use, so it's not practical to use with a large number of views, but will be useful for a few of your most-used views.

If you add the Change View command to the QAT (Quick Access Toolbar) accessing the lesser-used views will be a couple of steps less than using the View ribbon.
Add Current view command to the QAT

To use the macro, press Alt+F11 to open the VBA editor. Right click on Project1 and choose Insert > Module. Paste the macro into the new module, one for each button you want to create.

Make the following changes to each macro:

  • Change the macro name (Sub GetAssignedView()) so it is unique for each macro. I use the view name in the macro name.
  • Change the name of the view in each macro (Set objView = objViews.Item("Assigned")) to match the name of the desired view.
  • While Set objViews = Application.ActiveExplorer.CurrentFolder.Views allows the macro to work with the folder you are viewing, the view needs to be available for the selected folder. If it's not listed in Change Views when you are viewing the folder, it's not available.

Don't forget to check your macro security settings!

After creating your macros:

  1. Go to File, Options, Customize Ribbon or Quick Access Toolbar
  2. In Choose commands from select Macros
  3. Select your macro and click Add
  4. Repeat for each macro

Note: If you are adding the views to a ribbon, you need to add a New Group to either your most used tab or add a New Tab to add the group to.


Sub GetAssignedView()

 Dim objViews As Views
 Dim objView As View
 
' Applies view to select folder
 Set objViews = Application.ActiveExplorer.CurrentFolder.Views
 
 'Get the view 
 Set objView = objViews.Item("Assigned")

'apply the view
 objView.Apply
 
End Sub

 

Assign View to Folder and Subfolders

This macro applies the view to the selected folder and it's subfolders (but not nested subfolders), after first checking to see if the folder is the correct type (Contacts in this example.)

To use, select either the parent folder and run the macro.

Sub SetViewSubFolders()
 
 Dim CurrentFolder As Outlook.folder
 Dim i As Long
 
 Dim objViews As Views
 Dim objView As View
  
' Applies view to select folder
 Set CurrentFolder = Application.ActiveExplorer.CurrentFolder
 Set objViews = CurrentFolder.Views
  
 'Get the view
 Set objView = objViews.Item("Assigned")
 
'apply the view
 objView.Apply
 
For i = CurrentFolder.Folders.Count To 1 Step -1
 Set olNewFolder = CurrentFolder.Folders(i)
    For Each olNewFolder In CurrentFolder.Folders

' use if to apply to specific folder type
    If olNewFolder.DefaultItemType = olContactItem Then
        Debug.Print olNewFolder.Name
        Set objViews = olNewFolder.Views
        Set objView = objViews.Item("Assigned")
        objView.Apply
    End If
    Next
Next i

End Sub

Folder TypeDefaultItemType
CalendarolAppointmentItem
ContactsolContactItem
JournalolJournalItem
MailolMailItem
NotesolNoteItem
TasksolTaskItem

Apply a View to Nested Subfolders

This macro is based off of Michael Bauer's Folder: Expand all Folders macro and works on nested folders. The view is assigned in the LoopFolders macro.

Public Sub AssignViewtoFolders()
  On Error Resume Next
  Dim Ns As Outlook.NameSpace
  Dim Folders As Outlook.Folders
  Dim CurrF As Outlook.MAPIFolder
  Dim F As Outlook.MAPIFolder
  Dim ExpandDefaultStoreOnly As Boolean

  Set Ns = Application.GetNamespace("Mapi")
  Set CurrF = Application.ActiveExplorer.CurrentFolder

    Set F = Ns.GetDefaultFolder(olFolderInbox)
    Set F = F.Parent
    Set Folders = F.Folders
    LoopFolders Folders, True
    
  'DoEvents
  Set Application.ActiveExplorer.CurrentFolder = CurrF
End Sub

Private Sub LoopFolders(Folders As Outlook.Folders, _
  ByVal bRecursive As Boolean _
)
  Dim F As Outlook.MAPIFolder

  For Each F In Folders
    Set Application.ActiveExplorer.CurrentFolder = F
        
    If F.DefaultItemType = olContactItem Then
        Debug.Print F.Name
        Set objViews = F.Views
        Set objView = objViews.Item("Assigned")
        objView.Apply
    End If

    If bRecursive Then
      If F.Folders.Count Then
        LoopFolders F.Folders, bRecursive
      End If
    End If
  Next
End Sub

Use the Macro with Multiple Views

To use this code with multiple views, you can create a public string and use a macro to assign a View name to the string then call the assign view macro.

Like this:

Public strView As String

Sub NewView()
strView = "New View"
GetAssignedView
End Sub

Sub View1()
strView = "View1"
GetAssignedView
End Sub

Sub GetAssignedView()
 
 Dim objViews As Views
 Dim objView As View
  
' Applies view to select folder
 Set objViews = Application.ActiveExplorer.CurrentFolder.Views
  
 'Get the view
 Set objView = objViews.Item(strView)
 
'apply the view
 objView.Apply
  
End Sub

Open the Calendar pane to a specific Calendar and view

Use this code to open a specific calendar using a specific view every time you switch to the calendar module.

To use: paste into ThisOutlookSession, change the name of the view (it's case sensitive), then click in Application_Startup and click Run. Switch navigation pane folders to test.


Dim WithEvents objPane As NavigationPane
 
Private Sub Application_Startup()
    Set objPane = Application.ActiveExplorer.NavigationPane
End Sub
 
 
 
Private Sub objPane_ModuleSwitch(ByVal CurrentModule As NavigationModule)
  Dim objModule As CalendarModule
  Dim objGroup As NavigationGroup
  Dim objNavFolder As NavigationFolder
 
 If CurrentModule.NavigationModuleType = olModuleCalendar Then
     Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar)
     Set objGroup = objModule.NavigationGroups("My Calendars")
     
'' Change the 2 to start in a different folder
     Set objNavFolder = objGroup.NavigationFolders.Item(2)
     objNavFolder.IsSelected = True
  
 Dim objViews As Views
 Dim objView As View
 Set objViews = Application.ActiveExplorer.CurrentFolder.Views
 
 Set objView = objViews.Item("New view 4")
 objView.Apply
  End If

  
  Set objNavFolder = Nothing
  Set objGroup = Nothing
  Set objModule = Nothing
 End Sub

More Information

View Object (Outlook)

Apply a View to a Folder using a Macro was last modified: December 4th, 2018 by Diane Poremsky

Related Posts:

  • Use a macro to open the Calendar to appointment date
  • How to prevent changes to Outlook views
  • Select Multiple Calendars in Outlook
  • Apply custom views to all folders

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
15 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Peter (@guest_219103)
January 24, 2022 1:17 am
#219103

Thanks! This works well.

I now have a "WORKING" View showing only categorised emails. I can work in here easily without new emails popping in and breaking my concentration. I also have a "PROCESS NEW" View that shows uncategorised emails. Any new ones or ones that haven't been processed yet show up here.

0
0
Reply
Robert F (@guest_218486)
June 30, 2021 6:04 am
#218486

While it was helpful I found your article confusingly written. Example 1: Before you show any of the code for the macro you say, "Make the following changes to each macro" and then list changes that need to be made. Without having first seen the macro without the changes, there is no context. I find with instructions for anything it is far better to show what "X" is before telling the reader, "Change X as follows". Example 2: You write "Change the macro name (Sub GetAssignedView()) so it is unique for each macro. I use the view name in the macro name." What is the macro name? Is it the word "Sub" or "GetAssignedView" or ??? What text in that name am I supposed to change? Is the view name supposed to be inserted in the inner set of parentheses? Or should the text "GetAssignedView" be changed for the view name? Or ??? Example 3: You write, "Change the name of the view in each macro (Set objView = objViews.Item("Assigned")) to match the name of the desired view." Again, what text in that parenthetical should be changed? Should I just change "Assigned" to be the name of the desired view… Read more »

Last edited 3 years ago by Robert F
0
0
Reply
Witzker (@guest_210700)
March 25, 2018 12:08 pm
#210700

Hi
Is it possible to read all exiting vievs for contacts, open a box with the list to click on the view to show it up?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Witzker
March 26, 2018 12:37 am
#210704

To the best of my knowledge, no, not using VBA.

0
0
Reply
Stu (@guest_196313)
February 6, 2016 9:54 am
#196313

aloha Diane.. i am using the vba code to expand all the mail folders. It works perfectly on my PC, but when i try to apply the same to another PC, it fails. i remarked the "on error resume next" and a pop up shows the operation failed. when i debug, it highlights the following line. Set Application.ActiveExplorer.CurrentFolder = F the only difference between the 2 PC's is one has a microsoft exchange account. what am i missing? and thank you for your time and sharing your insight....i really appreciate it!!! Sub ExpandFolders() ' On Error Resume Next Dim Ns As Outlook.NameSpace Dim Folders As Outlook.Folders Dim CurrF As Outlook.MAPIFolder Dim F As Outlook.MAPIFolder Dim ExpandDefaultStoreOnly As Boolean ExpandDefaultStoreOnly = False Set Ns = Application.GetNamespace("Mapi") Set CurrF = Application.ActiveExplorer.CurrentFolder If ExpandDefaultStoreOnly = True Then Set F = Ns.GetDefaultFolder(olFolderInbox) Set F = F.Parent Set Folders = F.Folders LoopFolders Folders, True Else LoopFolders Ns.Folders, True End If DoEvents Set Application.ActiveExplorer.CurrentFolder = CurrF End Sub Private Sub LoopFolders(Folders As Outlook.Folders, _ ByVal bRecursive As Boolean _ ) Dim F As Outlook.MAPIFolder For Each F In Folders Set Application.ActiveExplorer.CurrentFolder = F DoEvents If bRecursive Then If F.Folders.Count Then LoopFolders F.Folders, bRecursive End If End… Read more »

0
0
Reply
Brent (@guest_196073)
January 22, 2016 3:04 pm
#196073

Hi Diane,
I am trying to come up with a Macro that specifically expands the In-Place Archive (Online Archive) and sub-folders on startup. Is there any code to accomplish this?
Thanks!

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Brent
January 22, 2016 10:14 pm
#196085

See if the macro here works with the archive folders - https://www.vboffice.net/en/developers/expand-all-folders/

0
0
Reply
phxphun (@guest_190939)
May 14, 2015 2:34 pm
#190939

I tend to prefer keeping my hands on the keyboard, so Alt+F1 followed by Ctrl+F1 is probably going to work best for me... with about the same effort as the reading button. Thanks for the suggestion though!

0
0
Reply
phxphun (@guest_190896)
May 12, 2015 6:38 pm
#190896

Hi Diane,

I have two basic modes in which I use Outlook - managing email and reading email. I like to set my Outlook view to best accommodate each mode. When I'm reading emails the Ribbon and Navigation Pane should both be hidden and unhidden all other times.

For quickly switching between my two views, I'd simply like to combine the functionality of Ctrl+F1 (Hide Ribbon) with the functionality of Alt+F1 (Hide Navigation Pane) into a single action.

Can this be done through a short macro assigned to a hotkey combination?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  phxphun
May 13, 2015 11:10 pm
#190930

No, it can't be automated... however have you tried the reading buttons in the status bar? It might not get you the exact format you want (the ribbon isn't affected) but should come close. It's the buttons in the status bar on the far right, next to zoom.

0
0
Reply
Phillip (@guest_188139)
December 13, 2014 8:19 pm
#188139

Hi,
I would like the macro to apply a specific view to all sub-folders in my inbox.
thanks,
Phil

0
0
Reply
Diane Poremsky (@guest_188143)
Reply to  Phillip
December 14, 2014 1:02 pm
#188143

I updated the article to include a macro to apply a view to the selected folder and subfolders.
https://www.slipstick.com/developer/apply-view-to-folder-using-vba/#subfolders

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 16

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Reset the New Outlook Profile
  • Save Attachments to the Hard Drive
  • Add Attachments and Set Email Fields During a Mail Merge
  • Outlook SecureTemp Files Folder
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment