Solved

VBA: Open and close a .pst file

Posted on 2006-06-15
8
6,401 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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.
If you don't know how to downgrade, my instructions below should be helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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: …

746 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

12 Experts available now in Live!

Get 1:1 Help Now