Checking for locked .pst file.

  • Thread starter Thread starter Steve Roberts
  • Start date Start date
S

Steve Roberts

I use the following code to open all of the .pst files in a user selected
folder. It works fine except when another user already has one of the .pst
files open. Is it possible to check for the file being locked before I try
to open it?

Thanks in advance for your suggestions!

Steve

Dim shell As Object
Dim objFolder As Object
Dim strFileNameWithPSTReplaced

Set shell = CreateObject("Shell.Application")

Set Folder = shell.NameSpace(txtFolderPath & "\")
Set items = Folder.items

For I = 0 To items.Count - 1

Set Item = items.Item(I)

If Not Item.IsFolder Then
Filename = Item.Path

If UCase(Right(Filename, 4)) = ".PST" Then
Application.Session.AddStore (Filename)

Set objFolder = Application.Session.Folders.GetLast '.GetLast Set
objFolder to last folder

strFileNameWithPSTReplaced = Replace(Item.Name, ".pst", "", , ,
vbTextCompare)

If objFolder.Name <> strFileNameWithPSTReplaced Then objFolder.Name =
strFileNameWithPSTReplaced

End If
End If
Next
 
Back
Top