我有以下代码但是我无法从浏览窗口获取文件列表(当选择多个文件时),我刚刚开始使用VB,所以请原谅任何明显的错误。
Private Sub cmdBrowse_Click()
Dim success As Boolean
success = browseFiles(Me.txtFile)
End Sub
Public Function browseFiles(tbx As TextBox) As Boolean
Dim fileDlg As Office.FileDialog
Dim theFile As Variant
' Clear the textbox contents.
tbx.Value = ""
' Instantiate the File Dialog.
Set fileDlg = Application.FileDialog(msoFileDialogFilePicker)
With fileDlg
' Set the title of the dialog box. '
.Title = "Please select one or more files"
' Clear the filters and add the ones you want.'
.Filters.Clear
'.Filters.Add "Access Databases", "*.ACCDB"
'.Filters.Add "Access Projects", "*.ADP"
'.Filters.Add "Text Files", "*.TXT"
'.Filters.Add "CSV Files", "*.CSV"
'.Filters.Add "Excel xlsx files", "*.XLSX"
'.Filters.Add "Excel files", "*.XLS"
'.Filters.Add "All Files", "*.*"
.Filters.Add "Jpeg Files", "*.JPEG"
.Filters.Add "Png Files", "*.PNG"
.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
'Get the selected file
For Each theFile In .SelectedItems
tbx.Value = theFile
Next
End If
End With
browseFiles = True
End Function