0
votes

I have two functions in VB that I use for archiving my emails on completed projects. The first opens either all of my previous year email stores, or just one at a time. These PST files are stored on Dropbox, so as soon as Outlook opens the PST files, it locks them and won't let Dropbox sync the files. Right now, I have a third routine that closes all open PST files, shuts Outlook down and calls a batch file that restarts outlook without the PST files open so that Dropbox can finish syncing.

Sub OPENALL()
    Application.GetNamespace("MAPI").AddStore "E:\2012.pst"
    Application.GetNamespace("MAPI").AddStore "E:\2013.pst"
    Application.GetNamespace("MAPI").AddStore "E:\2014.pst"
    Application.GetNamespace("MAPI").AddStore "E:\2015.pst"
    Application.GetNamespace("MAPI").AddStore "E:\2016.pst"
    Application.GetNamespace("MAPI").AddStore "E:\2017.pst"
    Application.GetNamespace("MAPI").AddStore "E:\2018.pst"
    Application.GetNamespace("MAPI").AddStore "E:\2019.pst"
    Application.GetNamespace("MAPI").AddStore "E:\2020.pst"
    Application.GetNamespace("MAPI").AddStore "E:\2021.pst"
End Sub

Sub CLOSEMSGSTORE()
    Dim objStores As Outlook.Stores
    Dim objStore As Outlook.store
    Dim objOutlookFile As Outlook.folder
    Dim i As Integer
 
    'Get All Outlook Files in Your Outlook
    Set objStores = Outlook.Session.Stores
 
    For i = objStores.Count To 1 Step -1
 
        Set objStore = objStores.item(i)
        Set objOutlookFile = objStore.GetRootFolder
 
        'Exclude the Outlook OST File for Exchange mailbox
        If objStore.ExchangeStoreType = olNotExchange Then
           'Close the PST File
           Outlook.Session.RemoveStore objOutlookFile
        End If
    Next
 
    Set objStores = Nothing
    Set objStore = Nothing
    Set objOutlookFile = Nothing
    
    Shell ("C:\Users\csalv\OneDrive\Documents\Computer Tweaks\outrestart.bat")
    Application.Quit
End Sub

Is there any way to force the file lock on the PST file to release without having to shut Outlook down? Thanks.