(Access) 的 Application.FileDialog 屬性

會傳回代表檔案對話方塊之單一執行個體的 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 支援與意見反應