Application.FileDialog 属性 (Access)

返回一个 FileDialog 对象,该对象表示文件对话框中的单个实例。 此为只读属性。

语法

表达式FileDialog (dialogType)

expression:表示 Application 对象的变量。

参数

名称 必需/可选 数据类型 说明
dialogType 必需 MsoFileDialogType 一个 MsoFileDialogType 常量,该常量代表对话框的类型。

备注

在 Microsoft Access 中不支持 msoFileDialogOpenmsoFileDialogSaveAs 常量。

请注意,使用“文件打开对话框”选择文件时,包含所选文件的目录将成为进程的当前目录。 这意味着目录将被锁定,直到当前模具发生更改或进程终止。 这将防止删除、移动或重命名目录。

示例

此示例演示如何使用 FileDialog 对象显示允许用户选择一个或多个文件的对话框。 然后将所选文件添加到名为 FileList 的列表框中。

Private Sub cmdFileDialog_Click() 
  
   ' Requires reference to Microsoft Office 11.0 Object Library. 
 
   Dim fDialog As Office.FileDialog 
   Dim varFile As Variant 
 
   ' Clear listbox contents. 
   Me.FileList.RowSource = "" 
 
   ' Set up the File Dialog. 
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker) 
 
   With fDialog 
 
      ' Allow user to make multiple selections in dialog box 
      .AllowMultiSelect = True 
             
      ' Set the title of the dialog box. 
      .Title = "Please select one or more files" 
 
      ' Clear out the current filters, and add our own. 
      .Filters.Clear 
      .Filters.Add "Access Databases", "*.MDB" 
      .Filters.Add "Access Projects", "*.ADP" 
      .Filters.Add "All Files", "*.*" 
 
      ' Show the dialog box. If the .Show method returns True, the 
      ' user picked at least one file. If the .Show method returns 
      ' False, the user clicked Cancel. 
      If .Show = True Then 
 
         'Loop through each file selected and add it to our list box. 
         For Each varFile In .SelectedItems 
            Me.FileList.AddItem varFile 
         Next 
 
      Else 
         MsgBox "You clicked Cancel in the file dialog box." 
      End If 
   End With 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。