Home » excel » excel – Having problems with .InitialFileName view with FileDialog command

excel – Having problems with .InitialFileName view with FileDialog command

Posted by: admin April 23, 2020 Leave a comment


So I am using the FileDialog to select a folder full of images that I am putting into a PowerPoint presentation and I am having problems getting the right initial view to come up.

Here is what I have

strFolder = InitDir
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)

With fldr
    .Title = "Select a Folder"
    .AllowMultiSelect = False
    .ButtonName = "Select"
    .InitialView = msoFileDialogViewList
    .InitialFileName = "C:\Users\Daniel\My Pictures\" 'using to test code

    If Right(strName, 1) <> "\" Then
        strFolder = strFolder & "\"
    End If
    If .Show <> -1 Then
        Exit Sub
        strFolder = .SelectedItems(1) & "\"
    End If
End With

If I exlude the “\” after “My Pictures”, all the folders in my user folder “Daniel” comes up in the initial view with “My Pictures” initially selected, but when I include the “\” after, what I presume is the “FileDialogViewList” just shows up. How do I get the “My Pictures” folder to come up initially.

How to&Answers:

The initialFileName that you have passed is incorrect that is why it is showing My Documents as an initial folder.Since in case of incorrect initialFileName default directory is shown.
Try following path:
C:\Documents and Settings\Daniel\My Documents\My Pictures\


I had the similar problem and during debugging noticed, that in the case when the file or folder path is the same as is set for the file dialog box object in the moment of this object initialization, initial file name ise set not to the one which you want but to a user Documents folder. To overcome this problem for me helped this code snippet:

If Not fDialog.InitialFileName = filePath Then
    fDialog.InitialFileName = filePath
End If