使用FileDialog命令遇到.InitialFileName视图时出现问题

所以我正在使用FileDialog来select一个文件夹,里面装满了我正在放入PowerPoint演示文稿的图像,并且遇到了出现正确的初始视图的问题。

这是我的

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 Else strFolder = .SelectedItems(1) & "\" End If End With 

如果我在“我的图片”之后排除了“\”,我的用户文件夹“Daniel”中的所有文件夹都会在初始视图中显示,最初select“我的图片”,但是当我包含“\”后,是“FileDialogViewList”刚刚出现。 如何获得“我的图片”文件夹最初出现。

您传递的initialFileName是不正确的,这就是为什么它显示我的文档作为初始文件夹。因为在不正确的initialFileName默认目录的情况下显示。 尝试以下path:C:\ Documents and Settings \ Daniel \ My Documents \ My Pictures \

我有类似的问题,在debugging过程中注意到,在文件或文件夹path与在对象初始化的时候为文件对话框对象设置的path相同的情况下,初始文件名被设置为不是你想但是到一个用户的文档文件夹。 为了克服这个问题,帮助我的代码片段:

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