Solved

VBA: Open and close a .pst file

Posted on 2006-06-15
8
6,730 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
Technology Partners: 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!

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Outlook Free & Paid Tools
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
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 …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

756 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