?
Solved

VBA: Open and close a .pst file

Posted on 2006-06-15
8
Medium Priority
?
7,031 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 76

Accepted Solution

by:
David Lee earned 1000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
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: …
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…
Suggested Courses

765 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