適用對象
應用程式物件 |
傳回代表單一檔案對話方塊執行個體的 FileDialog 物件。
expression.FileDialog(dialogType)
運算式 必要。 傳回 [套用至] 清單中其中一個對象的表達式。
dialogType 必要 MsoFileDialogType。 檔案對話方塊類型。
MsoFileDialogType 可為下列其中一種 MsoFileDialogType 常數。 |
msoFileDialogFilePicker |
msoFileDialogFolderPicker |
msoFileDialogOpen Microsoft Access 不支援。 |
msoFileDialogSaveAs Microsoft Access 不支援。 |
備註
msoFileDialogOpen 和 msoFileDialogSaveAs 在 Microsoft Office Access 2007 中不支援。
範例
此範例說明如何使用 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