Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB script to detach PST in Outlook 2003

Posted on 2011-03-09
5
Medium Priority
?
902 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
ID: 35087936
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
ID: 35088212
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
ID: 35095740
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 1000 total points
ID: 35098009
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
ID: 35099744
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
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 …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

877 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