Solved

VBA: Open and close a .pst file

Posted on 2006-06-15
8
6,796 Views
Last Modified: 2012-08-14
Hi Everyone,

Can someone tell me, or point to somewhere that tells, how to open a .pst file as a personal folder via VBA?  I'm assuming once I have that code I can figure out how to close it, I just cant figure it out and after a quick google search I couldnt find anything either.

If it helps, this is what I'm trying to accomplish via VBA code:

-Open "V:\personal\expo.pst"
-Move selected messages to that .pst file
-Close expo.pst

I'm pretty sure I can get steps 2 and 3 once I know how to open and reference the pst file/personal folder, just need the nudge in the right direction to open it.

EDIT: I'm using outlook 2000, if that helps.

Thanks!
Matt
0
Comment
Question by:mvidas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Expert Comment

by:AndreDekolta
ID: 16912691
.PSTs must be opened with Outlook.  Try outlook.exe V:\personal\expo.pst

Andre...
0
 
LVL 9

Expert Comment

by:AndreDekolta
ID: 16912711
<-Move selected messages to that .pst file> & <Close expo.pst>

Look at the Outlook command line switches in the Outlook Help File.  That should get you pointed in the right direction.

Andre...
0
 
LVL 35

Author Comment

by:mvidas
ID: 16912796
Hi Andre,

I will look at the help file as I've never looked into using the command line with outlook before, but I think you may have missed my point.  I'm looking for vba code to be run from within outlook, the above steps are just part of a much larger procedure.  I could open the .pst file as stated above, but would that only be for the newly created instance of outlook, or would it also carry over to the existing instance?
I just tried running
 outlook.exe V:\personal\expo.pst
And I got an error in outlook saying "Error performing inpage operation".  It didn't open a new instance though, which is good, I'm just wondering if I got the syntax wrong (the file path/name is correct--I just re-verified).

Matt
0
SendBlaster Pro 4 - Bulk Email Sending Software

SendBlaster 4 Pro - Best Bulk Emailing Sending Software
Automatic Subscribe / Unsubscribe Processing
Great for Newsletters & Mass Mailings
Optional HTML & Text Composition
Integration with Google Features
Built in Spam Score Checking
Free Professional Templates - Feature Packed!

 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 16915977
Greetings, mvidas.

This will get the jobs done.  Change the path and filename as needed.

Sub OpenPSTFile()
    Dim olkNS As Outlook.NameSpace
    Set olkNS = Application.GetNamespace("MAPI")
    olkNS.AddStore "C:\eeTesting\BlueDevilFan.pst"
    Set olkNS = Nothing
End Sub

Cheers!
0
 
LVL 9

Expert Comment

by:AndreDekolta
ID: 16916031
Cool!  Thanks BlueDevilFan, I learned something new too.  As you can see, I am no coder.

Andre...
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16916065
You're welcome, Andre.  
0
 
LVL 35

Author Comment

by:mvidas
ID: 16935172
Thanks, David!

I was able to accomplish my goal by using:

 Dim olFold As Variant, iMsg As Variant
 With Application.GetNamespace("MAPI")
  .AddStore "v:\personal\expo.pst"
  Set olFold = .Folders("Personal Folders").Folders("export") 'or .Folders.GetLast
  For Each iMsg In Application.ActiveExplorer.Selection
   If TypeName(iMsg) = "MailItem" Then
    iMsg.Move olFold
   End If
  Next
  .RemoveStore olFold
 End With

Unfortunately it did not work with my overall project (long story), but I'll still use part of it, plus I learned more about outlook vba.  
Thanks again!
Matt
0
 
LVL 76

Expert Comment

by:David Lee
ID: 16939133
You're welcome, Matt!  Glad I could help out.
0

Featured Post

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!

Question has a verified solution.

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

If you don't know how to downgrade, my instructions below should be helpful.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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…

738 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