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
Name | Enumeration | Description |
---|---|---|
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
Hi Diane. I have been using this incredible on open procedure for quite some time. I love it . TY! However, I see that it un-sets my calendar view in my to do pane on my tasks screen. Any way to adjust for this?
Isaac
'Private Sub Application_Startup()
'Dim objTasks As Folder
'Dim objInbox As Folder
'Dim olExp As Outlook.Explorer
'Set objInbox = Application.ActiveExplorer.CurrentFolder
'Set objTasks = Session.GetDefaultFolder(olFolderToDo)
'objTasks.Display
'Set olExp = Application.ActiveExplorer
'With olExp
' .WindowState = olMaximized
'End With
'objInbox.Display
'Set Application.ActiveExplorer.CurrentFolder = objInbox
'Set olExp = Application.ActiveExplorer
'olExp.WindowState = olMaximized
'End Sub
Hello Diane, I have shared a macro project to some colleagues (we are working with Outlook 2016). For some of them, the "Private Sub Application_Startup()" is not working. I do not understand why... I have checked on the PC of one of them, and the macros Outlook settings are good. I have tried to insert a "stop" into the code at the beginning of the procedure, relaunched Outlook, but nothing happened (the code even did not go until the "stop" point).
Do you have an idea about what could go wrong?
Thank you for your help.
Yohann
I don't understand how to use the (second) snippet. I tried replacing most of Application_Startup() with the snippet. Then testing it with F8 went ok. But when starting outlook outlook crashes and when starting it the second time it has turned off VBA. "Problem" is that when creating new window and changing it to calender, it gets the calender Icon in the taskbar. That doesn't work with the Application_Startup; they all have the mail-icon. One can live with that but would be nice if there was a solution.
I use a .vbs to close outlook:
Set objOutlook = CreateObject("Outlook.Application")
objOutlook.Quit
Set objOutlook = Nothing
and included it in other batchfiles (vbs) to restart and turn off the PC; all added as links in a folder on the taskbar. This way Outlook starts in the same mode when it was "quit". However when windows crashes or other moments you don't use a batch this is forgotten. Think I will stick to that for a while.
Thank you thank you thank you! This still works great for Outlook 2016. I can't tell you how much I appreciate this!
Hi Diane; I went back to this issue, and thought I would need to go first to Macros and CREATE a new one, which I did, calling it 'ThisOutlookSession.OpenTwoWindows'. That took me to the VBA editor, with the code of my original DeleteAttachments macro above a newly automatically inserted line after the entry 'End Sub' on that code. Under the line, there were two new sentences: 'Sub OpenTwoWindows' and 'End Sub'. I therefore copied and pasted the entire code you provided above between these two sentences, saved the newly edited VBA project, closed it, returned to Outlook and closed Outlook. When I opened Outlook again, it did what the code asked it to do - that is the good news! However, I do not want to open all 4 windows at Start-up, but only Inbox and Calendar. So, my intention was to edit the code to get rid of the other 2 windows I am not interested in. Tackling one variable at a time, the first modification I did was to remove all the entries for Tasks only, as on the attached Screenshot (I am not sure this attaching is working!... You may get multiple copies of the JPEG file… Read more »
Hi Diane; any chance of a reply, please?
Cheers.
Sorry I missed your questions earlier (too many comments, not enough time :)) although late, I will try to get your questions answered today.
I want to try this, as I am interested in having only 2 windows (Inbox and Calendar), automatically opening when I start Outlook. I think I know how to modify the text of the Macro you provided for my purposes.
My problem/doubt is: I already have a Macro in the Project1 (VBAProject.OTM)\Microsoft Outlook Objects\ThisOutlookSession. This is a macro called DeleteAttachment (which I got from you!) that instructs Outlook to add an entry onto the message to state that the attachment was deleted. How can I add a second Macro to the same session? Do I just copy and paste the text for the new Macro (as above, to open the two windows) at the end of the DeleteAttachment text? I imagine the answer is no, but I cannot figure out how to do it otherwise. I may be missing some very simple insight here... Thanks in advance for your invaluable help!
You can have more than one macro - they can be in one module or in different modules. (I like to use different modules, just to make it easier to find them. Outlook won't have a problems find them though.)
The is one exception - macros that run automatically. You can only have one of some of the auto macros; you can have multiple of others (like itemadd) as long as the names are different.
Thanks, Diane. In the meantime, I managed to edit the second macro to do what I wanted, and appended it to the end of the old one. It was a lot of trial and error to get the windows the preferred size, and I could never get them to come up exactly as I wanted: the Inbox opening with the left Folder panel visible and 'pinned', and the Calendar window without the visible Folder panel. I still have to do the pinning and and the hiding manually every time I open Outlook. Not a big drama, but a little frustrating for being 'beaten' by the inability to get it how I wanted! So, now I have 2 questions still on this matter: 1) How do I modify the macro to get that effect? 2) I would also like to have the two macros in different modules. At present they are consecutively written in the 'ThisOutlookSession'. Is the process just one of Copying the text of the second macro and Pasting it onto an empty Module 1? If yes, can I then delete that second macro from the ThisOutlookSession? I attach a screenshot of the current setup to show you the… Read more »
Hi Diana;
This macro, for opening multiple windows when Outlook starts, worked OK until recently. However, for the past 4 weeks or so, Outlook has repeatedly been crashing - it stops working, restarts by itself and, in doing so, it opens multiples of the multiple windows. Furthermore, it also loses my other configurations of the 'Customise' the Ribbon and the QuickAccess Toolbar. Could this be a 'late' (???) consequence of this macro, for some unknown reason? Or can you think of another reason why Outlook has become this unstable? I have tried to 'Repair' it via the Control Panel, but the problem was not solved. I also ran a MS Support and Recovery Assistant for Office 365 tool, and it did not solve it either.
My Outlook is 2016 on the Office 365 provided by my University on an Exchange server.
I look forward to hearing from you!
Junia.