" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 如何用<em>VBA</em>打开选择文件和选择路径的对话框-excel vba 文件对话框,v

如何用<em>VBA</em>打开选择文件和选择路径的对话框-excel vba 文件对话框,v

作者:乔山办公网日期:

返回目录:excel表格制作


Sub SelectFile()
Application.DisplayAlerts = False
fil = ThisWorkbook.Name
Filename = Application.GetOpenFilename("Excel 文件 ,*.xls;*.xlsx")
If Filename <> False Then
aFile = Split(Filename, "\")
sfilename = aFile(UBound(aFile))
End If
Workbooks.Open (Filename)
Workbooks(sfilename).Sheets(1).Cells.Copy Workbooks(fil).Sheets(1).Cells
Workbooks(sfilename).Close
Application.DisplayAlerts = True
End Sub

'在文件zhidao对话框对中返回选择一个文件夹的路径.Public Function ChooseFolder() As StringDim dlgOpen As FileDialogSet dlgOpen = Application.FileDialog(msoFileDialogFolderPicker)With dlgOpenIf .Show = -1 ThenChooseFolder = .SelectedItems(1)End IfEnd WithSet dlgOpen = NothingEnd Function'--------------------------------------------------------'在文件对话框对中,选择一个文件。
要复制其中的内容话,其实还是要打开的,只不过可以让你看不到,复制后就立即关闭,看起来像没打开一样。

Excel 开发人员参考
Application.Dialogs 属性
返回一个 Dialogs 集合,该集合表示所有内置对话框的。只读。
语法

表达式.Dialogs

表达式 一个代表 Application 对象的变量。

示例

本示例显示“文件”菜单的“打开”对话框。

Visual Basic for Applications
Application.Dialogs(xlDialogOpen).Show

搞一个事件引发Application.Dialogs(xlDialogOpen).Show 就会 弹出文件对话框
至于打开文件,要看你是这么打开的

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网