Consulting

Results 1 to 4 of 4

Thread: Add Data File Prorgammatically

  1. #1
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location

    Add Data File Prorgammatically

    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?

  2. #2
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    Update:
    If I add a *.pst file using the GUI and, while said *.pst is still attached (with top-level folder as "Personal folders"), run the VBA to attach the data files, the data files get attached properly.

  3. #3
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    We generate hundreds of *.pst files at a time. The VBA code I wrote attaches the *.pst files and then iterates over their contents to generate an analysis report for the person that generated the *.pst files to use for process validation. So this code needs to be able to dynamically add and remove stores at will.

    Any thoughts on how I can make sure the *.pst file gets added properly such that they always display as "Personal folders" with the correct folder structure and item content vs displaying as "Outlook Data File" without the proper folder structure and item content?

    Any help here would be greatly appreciated.

  4. #4
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    BUMP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •