打开Windows资源管理器并选择一个文件 [英] Open Windows Explorer and select a file

查看:163
本文介绍了打开Windows资源管理器并选择一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

查看此片段:

  Private Sub openDialog()
Dim fd As Office.FileDialog

设置fd = Application.FileDialog(msoFileDialogFilePicker)

带有fd

.AllowMultiSelect = False

'设置对话框的标题。
.Title =请选择文件。

'清除当前的过滤器,并添加我们自己的。
.Filters.Clear
.Filters.AddExcel 2003,* .xls
.Filters.Add所有文件,*。*

'显示对话框。如果.Show方法返回True,则
'用户至少选择一个文件。如果.Show方法返回
'False,用户点击取消。
如果.Show = True然后
txtFileName = .SelectedItems(1)'将txtFileName替换为您的文本框

如果
结束
End Sub

我认为这是你要求的。


Is there a way to open a Windows Explorer window from a vba form, navigate to a specific file and select it so that the file name is placed in a text box?

解决方案

Check out this snippet:

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

I think this is what you are asking for.

这篇关于打开Windows资源管理器并选择一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆