Open data file dialog

S

Steve Roberts

I have a form with a button that I want to program to open the open data
file dialog so the user can select a .pst file to open.
Is this possible do do this? If so can you point me in the right direction?

Thanks in advance

Steve
 
M

Michael Bauer

Hi Steve,

you could use the Commandbar technics. The FaceID for the "open .pst
button" is 5506.
 
S

Steve Roberts

Hey Michael,

I have spent the day reading and I can't seem to figure it out. All the
references I see point to using the command bar for placing stuff in a menu.
I'm sure it can't be as hard as i'm making it! Do you have any sample code?

Thanks
Steve
 
S

Steve Roberts

Sue,
I did a cut and paste from the example you refered me to and changed the
command bar ID to 5576
From what I can tell the code below should work but when I click the button
on my vb form it doesn't do anything. Any suggestions?


Private Sub btnOpenSingle_Click()

Dim objInsp
Dim colCB
Dim objCBB
On Error Resume Next
Set objInsp = Item.GetInspector
Set colCB = objInsp.CommandBars
Set objCBB = colCB.FindControl(, 5576)
If Not objCBB Is Nothing Then
objCBB.Execute
End If
Set objCBB = Nothing
Set colCB = Nothing
Set objInsp = Nothing

End Sub
 
S

Sue Mosher [MVP-Outlook]

This is a VB form or a custom Outlook form? If a VB form, then
Item.GetInspector is meaningless? If a custom Outlook form, does any code
run on the form at all? Is it published?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Steve Roberts

Hi Sue,

It's a VB form. Which I assume is what is causing me so much confusion.

Thanks for the help

Steve
 
S

Sue Mosher [MVP-Outlook]

Yup, that would certainly cause confusion. If you want to invoke the Open
Outlook Data File dialog itself and let Outlook do the actual opening, you
can use CommandBars techniques, but the base object needs to be
Application.ActiveExplorer, not an Inspector
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Steve Roberts

It seems to be working now with the code below. Is there a way to specify a
starting folder?

Private Sub btnOpenSingle_Click()

Dim oCtl As Office.CommandBarControl
Dim oPop As Office.CommandBarPopup
Dim oCB As Office.CommandBar

Set oCB = Application.ActiveExplorer.CommandBars("Menu Bar")
Set oPop = oCB.Controls("File")
Set oCtl = oPop.Controls("Open")
Set oCtl1 = oCtl.Controls("Outlook Data &File...")

oCtl1.Execute

End Sub
 
S

Sue Mosher [MVP-Outlook]

No.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Steve Roberts

Ok Thanks for your help.

I also found this bit of code that works pretty well if you need to start at
a specific folder.
A mix of my own stuff and info I got from
http://blogs.msdn.com/gstemp/archive/2004/02/17/74868.aspx

Dim Filename As String
Dim olApp As Outlook.Application
Dim MyNameSpace As Outlook.NameSpace


Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "Personal Folders|*.pst|"
objDialog.InitialDir = "G:\Archive_Emails"
intResult = objDialog.ShowOpen

If intResult = 0 Then

Exit Sub

Else

Filename = objDialog.Filename

Set olApp = CreateObject("Outlook.Application")
Set MyNameSpace = olApp.GetNamespace("MAPI")

MyNameSpace.AddStore Filename
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top