Solved

outlook script to attach pst files

Posted on 2009-04-15
6
2,232 Views
Last Modified: 2012-05-06
I'm looking for some code that could help me in getting this job done; Import all pst files available in a shared folder into outlook. I have 300 pst files that I need to attach to outlook for indexing.

thanks in advance.
0
Comment
Question by:stasila2010
  • 3
  • 3
6 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24150440
Hi, stasila2010.

What version of Outlook?  By "import" you mean you want the PSTs connected to Outlook?  You aren't looking to actually import their contents into another PST or your mailbox, right?
0
 

Author Comment

by:stasila2010
ID: 24150460
I'm using outlook 2003 right now and If I need to I can use 2007. yes I just want to connect them to outlook all at once. by default I can only select one and then another one and so on.

thanks for your help
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 24153388
Here's the code.  Follow these instructions to use it.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor
10. Run the macro
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:stasila2010
ID: 24157602
thank you very much for your VB script. I did worked but only added around 10 PST files to my outlook and then ended with Run-time error '-901758971 (ca404005)':
0
 

Author Comment

by:stasila2010
ID: 24159971
got it. your script works perfect.
thanks a lot.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24160352
You're welcome.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
Read this checklist to learn more about the 15 things you should never include in an email signature.
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: …
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…

776 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