Application.FileDialog 未引用?

问题描述 投票:0回答:2

由于我的研究使我相信我的参考资料可能与此有关,所以这里是我对 MS Access 的参考资料:

  • Visual Basic 应用程序
  • Microsoft Access 16.0 对象库
  • OLE 自动化
  • Microsoft Office 16.0 Access数据库引擎对象库
  • Microsoft Office 16.0 对象库

我的问题是我试图仅将文件对话框作为函数调用,返回值是所选的字符串路径。我从

开始
Dim fd as filedialog

Set fd = Application.filedialog(msoFileDialogSave)
With fd

...

现在,dim 的决定很好,但是“set”行给出了一个错误,指出对象“_application”的方法 filedialog 不成功。

我在这里看过类似的问题,但没有成功。 我期望实现我的目标

vba ms-access reference filedialog
2个回答
0
投票

您可以使用此代码:

   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 对象库”


0
投票

您的引用看起来不错,但您必须使用正确的常量:

如您所见,使用它是

..SaveAs

© www.soinside.com 2019 - 2024. All rights reserved.