[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBA: Open and close a .pst file

Posted on 2006-06-15
8
Medium Priority
?
7,161 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 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
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…

656 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