In TestDefaultFldr()
I set Fldr
to the default Inbox. The constant olFolderInbox
can be replaced by other values giving access to any of the default folders. If you type Set Fldr = Session.GetDefaultFolder(
, the VB editor will display a drop down list of all the possible values.
Sub TestDefaultFldr()
Dim Fldr As Folder
Set Fldr = Session.GetDefaultFolder(olFolderInbox)
Debug.Print Join(GetFldrNames(Fldr), "|")
End Sub
On my laptop, TestDefaultFldr()
displays Outlook data file|Inbox
which came as a surprise. I wrote GetFldrNames(Fldr)
to make sure that the folder I had referenced was the one I wanted. I had accessed the default Inbox and found it was empty! Store “Output data file” came with the default installation and I had ignored it since Outlook had created a store for each of my email accounts. It was only after discovering my empty default Inbox that I thought about how Outlook would know which of my email accounts was the account I would want as the default. Of the standard Outlook folders, there is either no default or the default is within “Output data file”. It may be possible to change which Inbox is the default Inbox but I have not investigated because I am not sure which of my email accounts I would make the default if I did change. Just remember that all your Calendar Items, Tasks and so on are within “Outlook data file” and make sure you include “Outlook.pst” in your archive list.
Most Outlook objects have the property Parent
. GetFldrNames(Fldr)
records the name of the folder in an array before trying to access its parent. It loops adding names to the end of the array until it reaches the store. The store does not have a parent so the attempt to access it fails. The sequence of names in the array is reversed and then returned to the caller. I have used Join
to turn the array of names into a displayable string.