[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Remove all pst files that are connected to the outlook.

Posted on 2009-04-16
7
Medium Priority
?
572 Views
Last Modified: 2012-05-06
Hi,

Remove all pst files that are connected to the outlook.
below is the script from David want the same script to be capable of removing all pst's when ever required and add them too.

Regards
Sharath
Sub OpenPSTs()
    Dim objFSO As Object, objFolder As Object, objFile As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Change the folder path on the next line'
    Set objFolder = objFSO.GetFolder("C:\SomeFolderName")
    For Each objFile In objFolder.Files
        If LCase(objFSO.GetExtensionName(objFile.Name)) = "pst" Then
            Outlook.Application.Session.AddStore objFile.Path
        End If
    Next
    Set objFolder = Nothing
    Set objFSO = Nothing
    MsgBox "Done"
End Sub

Open in new window

0
Comment
Question by:bsharath
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24163280
Hi, sharath.  

You want another script, like this one, only it removes all the PSTs, right?
0
 
LVL 11

Author Comment

by:bsharath
ID: 24164867
Yes David...But it would be useful like 1 script to add and to remove as well. Run once it add's the pst's and 2nd run remove all pst's
0
 
LVL 11

Author Comment

by:bsharath
ID: 24164868
Yes David...But it would be useful like 1 script to add and to remove as well. Run once it add's the pst's and 2nd run remove all pst's
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 24172955
Sharath,

This code will close all open PST files.  It's better to keep the two processes separate.  If you need to run them both, then you can call one and then the other.
Sub ClosePSTs()
    Dim olkStore As Outlook.Store, intIndex As Integer
    For intIndex = Outlook.Session.Stores.Count To 1 Step -1
        Set olkStore = Outlook.Session.Stores.Item(intIndex)
        If olkStore.ExchangeStoreType = olNotExchange Then
            Outlook.Session.RemoveStore olkStore.GetRootFolder
        End If
    Next
    Set olkStore = Nothing
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 24174818
Thanks David
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24175087
You're welcome, Sharath!
0
 
LVL 11

Author Comment

by:bsharath
ID: 24175091
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
This article will help to fix the below errors for MS Exchange Server 2016 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question