应用对象Microsoft 365 专属 Access Access 2024 Access 2021 Access 2019 Access 2016

适用于

Application 对象

返回表示字段对话框的单个实例的 FileDialog 对象。

表达式.FileDialog(dialogType)

表达式 必需。 返回“适用范围”列表中的对象之一的表达式。

dialogType    必需的 MsoFileDialogType 。 文件对话框的类型。

MsoFileDialogType 可以为以下任一 MsoFileDialogType 常量。

msoFileDialogFilePicker

msoFileDialogFolderPicker

msoFileDialogOpen Microsoft Access 中不支持。

msoFileDialogSaveAs Microsoft Access 中不支持。

备注

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", "*.ACCDB"
      .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

需要更多帮助?

需要更多选项?

了解订阅权益、浏览培训课程、了解如何保护设备等。