open outlook data files from vbscript / macro?

  • Thread starter Thread starter Mad Scientist Jr
  • Start date Start date
M

Mad Scientist Jr

Can someone post code that can be used in a macro to do the same thing
in Outlook as

File > Open > Outlook Data File > C:\Documents and Settings\joeblow\My
Documents\joeblow_personal_mail.pst

File > Open > Outlook Data File > C:\Documents and Settings\joeblow\My
Documents\Folder 1\joeblow_junk_mail.pst

File > Open > Outlook Data File > C:\Documents and Settings\joeblow\My
Documents\Folder 2\joeblow_office_mail.pst

to open all 3 mail files (and if possible, expand the folders) in one
click of a macro button?

Much appreciated..
 
I know this post is old but hopefully its still active enough to get a response. Mad Scientist, were you able to get this working? If so, could you be so kind as to provide the script or explain in more detail how to implement "Session.AddStore PSTName "C:\mystore.pst"" into vbscript as I am really new to this but would like to accomplish the exact same thing you were wanting.
 
Probably too late for Phoenix but seing as this thread has been a slow burner, it might be useful for someone else.

Here's a quick example:

Code:
Sub OpenPst
Session.Addstore ("C:\Filename.pst")
End Sub

I have quite a large number of PST files saved on a network location and every time I move PC's (quite regularly) it takes me 10 mins to get them all open. Here's a macro I put together today to automate this task.

Code:
Sub pstopen()
Dim NamesofPSTFiles() As Variant
'This will hold the names of the PST Files I want opened
Dim Counter As Long
NamesofPSTFiles = Array("NameofFirstPSTFile", "NameofSecond", "etc")
'This assumes that all the PST Files are in the same place but the code could be modified to include the full directory location in the names here (by removing the directory reference lower down)
For Counter = 0 To UBound(NamesofPSTFiles)
'Cycle through the names in the list above
DoEvents
'opening the files can take a while on network locations so this allows other processes to continue while the macro runs
'Check whether the name of the pst file exists - otherwise Session.AddStore will create a new PST file with the specified name
If Dir("U:\Outlook Data Files\" & NamesofPSTFiles(Counter) & ".pst") <> "" Then
Session.AddStore ("U:\Outlook Data Files\" & NamesofPSTFiles(Counter) & ".pst")
 Else: MsgBox (NamesofPSTFiles(Counter) & " was not found in the specified location. Click Ok to continue")
End If
Next
End Sub
 
Back
Top