由于我的研究使我相信我的参考资料可能与此有关,所以这里是我对 MS Access 的参考资料:
我的问题是我试图仅将文件对话框作为函数调用,返回值是所选的字符串路径。我从
开始Dim fd as filedialog
Set fd = Application.filedialog(msoFileDialogSave)
With fd
...
现在,dim 的决定很好,但是“set”行给出了一个错误,指出对象“_application”的方法 filedialog 不成功。
我在这里看过类似的问题,但没有成功。 我期望实现我的目标
您可以使用此代码:
Dim f As Office.FileDialog
Dim varItem As String
Set f = Application.FileDialog(msoFileDialogFilePicker)
With f
.Title = "My Title"
.AllowMultiSelect = False 'or true
.ButtonName = "Select" 'give any name
.Filters.Clear 'clear filter before set new ones
.Filters.Add "Excel files", "*.xl*" 'then create new ones
.Filters.Add "Word files", "*.do*"
.Filters.Add "Access files", "*.mdb; *.accdb"
.FilterIndex = 2 'pre-select one filter
.InitialFileName = "D:\" 'start directory
If .Show Then
' In case of Multiselect use this code
For Each varItem In f.SelectedItems
Debug.Print varItem
Next varItem
' In case of no MultiSelect use this code
SelectedFileName = f.SelectedItems(1)
Else
' User selected cancel
EndIf
End With
End Function
其他选项:
需要参考“Microsoft Office 对象库”