Scripting: Remove all PST files in an outlook profile

Building on, this code will remove the mapping that has been done in outlook for ALL PST files.

'On Error resume next
Dim objOutlook 'As Outlook.Application
Dim Session 'As Outlook.NameSpace
Dim Store 'As Outlook.Store
Dim Stores 'As Outlook.Stores
Dim objFolder 'As Outlook.Folder
Set objOutlook = CreateObject("Outlook.Application")
Set Session = objOutlook.Session
Set Stores = Session.Stores
For Each Store In Stores
If Store.ExchangeStoreType = 3 then
   Set objFolder = store.GetRootFolder
   Session.RemoveStore objFolder
End If
Comments (6)

  1. Anonymous says:

    Work with pst files by outlook 2007 ost repair

  2. mhaner says:

    I get an error line 10 char 1 Object doesn't support this property or method: 'Stores'

    Code 800a01b6

  3. Marc says:

    Odd… Do you have outlook installed on your pc? Script was tested on outlook 2003 and 2010 so something must be going on in your environment…

  4. Huey says:

    It works except it skipped every other PST file

  5. Kalle Lundberg says:

    This script uses a For Each-statement to traverse the list, but inside the loop items may be removed. The element after the deleted one will never be tested for deletion.

    See this page for a better script:…/script-fr-att-stnga-alla-ppna-pst-filer

  6. Jeff-ITman says:

    this is cool but only runs when outlook is closed

Skip to main content