I have a program that generates a *.pst file from email data stored in a database.
When I manually attach the *.pst file as follows, the top-level folder shows as "Personal folders" and has all the sub-folders and their contained items like they should:
Click File-->Account Settings-->Accoutn Settings...
Click "Data Files" tab
Click "Add..."
Choose "outlook data file (.pst)" and click "OK"
Navigate to and choose *.pst file in "Create or Open Outlook Data File" dialog and click "OK"
If I use VBA to do this, the top-level folder sometimes displays as "Outlook Data File" and only contains a "Deleted Items" and "Search Folders" folder.
However, sometimes it displays as "Personal folders" and contains the Inbox (and all other sub-folders).
I'm talking about the same *.pst file in both instances.
Here is the VBA I am using to add the data files:
Public Sub AddStores(folderPath As String)
Dim MyObj As Object, MySource As Object
Dim file As Variant
Dim olkNS As Outlook.NameSpace
Set olkNS = Application.GetNamespace("MAPI")
file = Dir(folderPath)
While (file <> "")
If ".pst" = LCase(Right$(file, 4)) Then olkNS.AddStoreEx file, olStoreDefault
file = Dir
Wend
Set olkNS = Nothing
End Sub
How can I use VBA to attach the data file so that the root folder is "Personal folders" and all the sub-folders display and are available?