Solved

outlook script to attach pst files

Posted on 2009-04-15
6
2,250 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

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

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
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…

839 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