Affichage des articles dont le libellé est Initial folder of open file dialog. Afficher tous les articles
Affichage des articles dont le libellé est Initial folder of open file dialog. Afficher tous les articles

Initial folder of open file dialog

lundi 27 avril 2015

Hello Experts,
I am trying to display an open file dialog window so that the user can pick up a file. I wish the window to show a specific folder. How can I do this? The code I am using is below. The parameter InitialFileName has no effect on the outcome. Any help is welcome.

Code:

Function GetFileName(strPath As String, imtype As String) As String
On Error GoTo Err_GetFileName
    Dim Dlg As FileDialog
    Dim sfl As FileDialogSelectedItems
    Dim sflitem As Variant
    Set Dlg = Application.FileDialog(msoFileDialogFilePicker)
    Set sfl = Dlg.SelectedItems
    GetFileName = " "
    Dlg.title = "Select the " & imtype & " file you want to access"
    Dlg.InitialFileName = strPath
    Dlg.ButtonName = "Select " & imtype
    Dlg.AllowMultiSelect = False
    Dlg.Filters.Clear
    Dlg.Filters.Add "Accepted", "*." & imtype
   
    If Dlg.Show = True Then
        sflitem = Dlg.SelectedItems(1)
        GetFileName = CStr(sflitem)
    Else
        MsgBox "no item selected - cancelled", , G_title
        GoTo Err_GetFileName
    End If
    Exit Function
Err_GetFileName:
    MsgBox Err.Description & " " & Err
    GetFileName = "ERROR"
    Exit Function
Ex_GetFileName:
    Set Dlg = Nothing
    Set sfl = Nothing
End Function

Initial folder of open file dialog

Labels