Checking for locked .pst file.

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
 
K

Ken Slovak - [MVP - Outlook]

Just try to open it in your code and handle any error that occurs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top