An Outlook user wants to open his Calendar, Contacts, Tasks, and Inbox in a specific order and with specific window sizes when he opens Outlook.
Is it possible to automatically open up four Outlook windows in a particular order (mail, calendar, contacts and tasks) and size?
While you can use the instructions at How to Open Multiple Outlook Windows to open multiple windows when you start Outlook, you don't have a lot of control over the order the windows open or their size. If you close some windows before exiting Outlook, you'll need to re-open those windows.
But with VBA almost anything is possible.
This startup macro will open the windows in the order listed when Outlook starts up. Each window can have a unique size and position. When the macro is finished, the Inbox is brought into focus and maximized.
Tip: to get the window size and position, adjust the windows on screen and take a screenshot. Use Snagit or another image editor to find the position (in pixels) of the upper left corner of each window and the window size. (Or use an on-screen ruler.)
As written, this macro assumes you have Outlook starting up in the Inbox (in File, Options, Advanced) and want it maximized. If you start up in a different folder, adjust the object names as needed.
Private Sub Application_Startup() Dim objCalendar As Folder Dim objTasks As Folder Dim objContacts As Folder Dim objInbox As Folder Dim olExp As Outlook.Explorer Set objInbox = Application.ActiveExplorer.CurrentFolder Set objCalendar = Session.GetDefaultFolder(olFolderCalendar) Set objContacts = Session.GetDefaultFolder(olFolderContacts) Set objTasks = Session.GetDefaultFolder(olFolderTasks) 'Set objInbox = Session.GetDefaultFolder(olFolderInbox) objTasks.Display Set olExp = Application.ActiveExplorer With olExp .WindowState = olMinimized End With objCalendar.Display Set olExp = Application.ActiveExplorer With olExp .WindowState = olNormalWindow .Top = 0 .Left = 0 .Height = 1200 .Width = 800 End With objContacts.Display Set olExp = Application.ActiveExplorer With olExp .WindowState = olNormalWindow .Top = 0 .Left = 800 .Height = 1200 .Width = 800 End With objInbox.Display Set Application.ActiveExplorer.CurrentFolder = objInbox ' olMaximized Set olExp = Application.ActiveExplorer olExp.WindowState = olMaximized End Sub
|olMaximized||0||The window is maximized.|
|olMinimized||1||The window is minimized.|
|olNormalWindow||2||A "normal" window open on screen. It's not minimized or maximized.|
This snippet opens the windows then offsets each window from the previous window, with the Inbox on top.
objTasks.Display objCalendar.Display objContacts.Display Dim olExps As Outlook.Explorers Set olExps = Application.Explorers Dim lTop As Long, lLeft As Long lTop = 200 lLeft = 200 For x = 1 To olExps.Count With olExps.Item(x) .WindowState = olNormalWindow .Top = lTop .Left = lLeft .Height = 700 .Width = 1000 End With lTop = lTop + lTop * 0.25 lLeft = lLeft + lTop * 0.25 Next x Set Application.ActiveExplorer.CurrentFolder = objInbox End Sub
How to use the macros on this page
First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.
To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look 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.
Macros that run when Outlook starts or automatically need to be in ThisOutlookSession.
The macros on this page need to go into ThisOutlookSession.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the macro code in ThisOutlookSession:
- Expand Project1 and double click on ThisOutlookSession.
- Copy then paste the macro into ThisOutlookSession. (Click within the code, Select All using Ctrl+A, Ctrl+C to copy, Ctrl+V to paste.)
More information as well as screenshots are at How to use the VBA Editor