views:

373

answers:

2

I'm working on an Outlook add-in that requires the Office specific FileDialog to interoperate with a Sharepoint site; the common file dialog doesn't have the interoperability. I know that both Word and Excel have a get_fileDialog method under Globals.ThisAddIn.Application.Application, but Outlook doesn't seem to. How do I launch an Outlook FileDialog? Is it even possible?

+1  A: 
'Add a "Module". Then add the declarations like this to it.

Option Explicit
Private Declare Function GetOpenFileName _
                Lib "comdlg32.dll" _
                Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

Public Function MyOpenFiledialog() As String
    Dim OFName As OPENFILENAME
    OFName.lStructSize = Len(OFName)
    'Set the parent window
    OFName.hwndOwner = Application.hWnd
    'Set the application's instance
    OFName.hInstance = Application.hInstance
    'Select a filter
    OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
    'create a buffer for the file
    OFName.lpstrFile = Space$(254)
    'set the maximum length of a returned file
    OFName.nMaxFile = 255
    'Create a buffer for the file title
    OFName.lpstrFileTitle = Space$(254)
    'Set the maximum length of a returned file title
    OFName.nMaxFileTitle = 255
    'Set the initial directory
    OFName.lpstrInitialDir = "C:\"
    'Set the title
    OFName.lpstrTitle = "Open File - VB Forums.com"
    'No flags
    OFName.flags = 0
    'Show the 'Open File'-dialog
    If GetOpenFileName(OFName) Then
        MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
        MyOpenFiledialog = Trim$(OFName.lpstrFile)
    Else
        MsgBox "Cancel was pressed"
        MyOpenFiledialog = vbNullString
    End If
End Sub 'Usage:
Private Sub Command1_Click()
    Text1.Text = MyOpenFiledialog
End Sub
MaSuGaNa
Outlook does not support FileOpen dialogues off Application.Also www.slipstick.com is the best Outlook developers site for tips and code.
MaSuGaNa
I probably should have mentioned I'm using VSTO, not VBA. In any case, I dno't think makign my own dialog box would help since it needed the really specific SharePoint functionality that the Office dialog box provided.
matthews
Doesn't seem to work for me (Outlook 2007) ? I think there is a minor Typo in that the Function 'MyOpenFiledialog()' is terminated with an 'End Sub' - but I changed this to 'End Function' and now receive the error //Run-time error '438': Object doesn't support this property or method// - pressing 'DEBUG' takes me to the line //OFName.hwndOwner = Application.hWnd//
monojohnny
A: 

Microsoft Common Dialog

If you have COMDLG32.OCX ("Common Dialog ActiveX Control") installed, then you can use this - it's explained here, with an example. (Scroll down just past the screenshot entitled "FIGURE 2: Don't try to select more than one file in Word! ").

monojohnny