Solved

VB script to detach PST in Outlook 2003

Posted on 2011-03-09
5
845 Views
Last Modified: 2012-05-11
I have over 300 mailboxes that are on an Exchange 2003 server, that I need to move to Exch2007.  Before I do this, I need to drop the active PST from that user's Outlook session.  I see a VB script to attach one, but I need a script that detaches the active PST for Outlook 2003.  I have one for Outlook 2007, but it won't run on 2003 - hence need a separate VB script to do this.
0
Comment
Question by:Monterio
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:Monterio
Comment Utility
I intend to run this script on the users machine directly, so I don't need to do this to 300 machines or something crazy like that - just one machine/mailbox at a time.
0
 
LVL 11

Expert Comment

by:TheGorby
Comment Utility
This looks like it might get the job done:

http://blogs.msdn.com/b/brijs/archive/2009/05/06/remove-all-pst-from-the-outlook-mailbox-using-vbscript.aspx

I'm not sure which, if not all, versions of Outlook this will work on.
0
 
LVL 1

Author Comment

by:Monterio
Comment Utility
Hi!

Thanks for the suggestion.  The thing I see in this article is that some of the code is cut off on a couple of lines.  I'm no scripter, but I do remember that conditional statements have beginning and ending elements.  There's an incomplete If/And/Then statement...the code's cut-off so I don't know what the rest of that statement is supposed to be.  I know enough that the script will fail as it currently is.  Can you complete the rest of that script so that I have everything for it to run successfully?  I cannot test it as it is unfortunately.
0
 
LVL 11

Accepted Solution

by:
TheGorby earned 250 total points
Comment Utility
It certainly is cut off, sorry for not catching that before. I'm not yet at a place where I can test this but I think this should work:
'Sample script to remove Personal Folders files (.pst) from the current MAPI profile or session
RemoveAllPST 

Sub RemoveAllPST()
Dim objOL 'As New Outlook.Application
Dim objFolders 'As Outlook.MAPIFolders
Dim objFolder 'As Outlook.MAPIFolder
Dim i 'As IntergerDim strPrompt 'As String 

Set objOL = CreateObject("Outlook.Application")
Set objFolders = objOL.Session.Folders
For i = objFolders.Count To 1 Step -1
	On Error Resume Next
    Set objFolder = objFolders.Item(i)
	'Prompt the user for confirmation
    If (InStr(1, objFolder.Name, "Mailbox") = 0) And (InStr(1, objFolder.Name, "Public Folders") = 0) Then
		strPrompt = ""
		strPrompt = "Are you sure you want to remove " & objFolder.Name
		If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
			objOL.Session.RemoveStore objFolder
		End If
    End If
Next
End Sub

Open in new window

0
 
LVL 11

Expert Comment

by:TheGorby
Comment Utility
I just noticed an error I made in copying/pasting the script on line 8... but hey if it's working for you then no big deal! Just in case though, here it is corrected:
'Sample script to remove Personal Folders files (.pst) from the current MAPI profile or session  
RemoveAllPST   
  
Sub RemoveAllPST()  
Dim objOL 'As New Outlook.Application  
Dim objFolders 'As Outlook.MAPIFolders  
Dim objFolder 'As Outlook.MAPIFolder  
Dim i 'As Interger
Dim strPrompt 'As String   
  
Set objOL = CreateObject("Outlook.Application")  
Set objFolders = objOL.Session.Folders  
For i = objFolders.Count To 1 Step -1  
    On Error Resume Next  
    Set objFolder = objFolders.Item(i)  
    'Prompt the user for confirmation  
    If (InStr(1, objFolder.Name, "Mailbox") = 0) And (InStr(1, objFolder.Name, "Public Folders") = 0) Then  
        strPrompt = ""  
        strPrompt = "Are you sure you want to remove " & objFolder.Name  
        If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then  
            objOL.Session.RemoveStore objFolder  
        End If  
    End If  
Next  
End Sub

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Find out how to use dynamic social media in email signatures with this top 10 DOs & DON’Ts.
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now