The title is pretty self-explanatory.
I want the macro to open a specific mailbox and then maximize that newly created explorer window so that the mailbox that was just opened is full-screen.
Here is the code I have so far:
Public Sub openMasterfiles()
' Define Variables
Dim olNS As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
' Set objects
Set olNS = GetNamespace("MAPI")
Set myFolder = olNS.Folders("Masterfiles").Folders("Inbox")
' Display the second mailbox
myFolder.Display
' ###Atttempting to set the new mailbox to the active explorer here
Set Application.ActiveExplorer.CurrentFolder = myFolder
' Attempting to maximize the newly opened mailbox here. This code _
only maximizes the exisiting explorer. Not the new one.
Application.ActiveWindow.WindowState = olMaximized
End Sub
All this manages to accomplish is to open the new mailbox ("Masterfiles") and maximize the prior Outlook window, not the newly opened one.
Thanks in advance!
CodePudding user response:
First of all, to get the Inbox
folder you need to use the NameSpace.GetDefaultFolder method which returns a Folder
object that represents the default folder of the requested type for the current profile.
If you need to get the Inbox
folder from an additional store you can use the Store.GetDefaultFolder method which returns a Folder
object that represents the default folder in the store and that is of the type specified by the FolderType
argument.
But the key thing here is that you need to use the Activate method of the Explorer
class which activates an explorer window by bringing it to the foreground and setting keyboard focus.
' Display the second mailbox
myFolder.Display
Set Application.Explorers.Item(2).CurrentFolder = myFolder
Application.Explorers.Item(2).Activate
' Attempting to maximize the newly opened mailbox here. This code _
only maximizes the exisiting explorer. Not the new one.
Application.ActiveWindow.WindowState = olMaximized
You may also check whether it is a second explorer window checking the Explorers.Count
property which returns an integer indicating the count of objects in the specified collection.
CodePudding user response:
You can use Explorers.Add
, which takes MAPIFolder
as an argument:
set expl = Application.Explorers.Add(myFolder, olFolderDisplayNormal)
expl.Display
expl.WindowState = olMaximized