【问题标题】:Open Windows Explorer and select a file打开 Windows 资源管理器并选择一个文件
【发布时间】:2012-05-05 12:10:52
【问题描述】:

有没有办法从 vba 表单打开 Windows 资源管理器窗口,导航到特定文件并选择它,以便将文件名放在文本框中?

【问题讨论】:

  • 在 VBA Excel 中按魔术键 F1 并搜索 Application.GetOpenFilename ;)

标签: vba excel


【解决方案1】:

看看这个sn-p:

Private Sub openDialog()
    Dim fd As Office.FileDialog

    Set fd = Application.FileDialog(msoFileDialogFilePicker)

   With fd

      .AllowMultiSelect = False

      ' Set the title of the dialog box.
      .Title = "Please select the file."

      ' Clear out the current filters, and add our own.
      .Filters.Clear
      .Filters.Add "Excel 2003", "*.xls"
      .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
        txtFileName = .SelectedItems(1) 'replace txtFileName with your textbox

      End If
   End With
End Sub

我想这就是你想要的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 2014-06-25
    • 2016-11-08
    • 2011-08-11
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    相关资源
    最近更新 更多