Excel 开发zhidao人员" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 如何实现:编写vba 弹出文件对话框,并打开选中文件?-excel 文件打开对话框,怎么调出excel对话框

如何实现:编写vba 弹出文件对话框,并打开选中文件?-excel 文件打开对话框,怎么调出excel对话框

作者:乔山办公网日期:

返回目录:excel表格制作


都不是!而是你用什么工具“清理,优化”把有用的都“优化掉”了!

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

表达式.Dialogs

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

示例

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

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

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

'Declare a variable as a FileDialog object.
Dim fd As FileDialog

'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)

'Declare a variable to contain the path
'of each selected item. Even though the path is aString,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant

'Use a With...End With block to reference the FileDialog object.
With fd

'Allow the selection of multiple files.
.AllowMultiSelect = True

'Use the Show method to display the file picker dialog and return the user's action.
'If the user presses the button...
If .Show = -1 Then

'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems

'vrtSelectedItem is aString that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example displays the path in a message box.
MsgBox "Selected item's path: " & vrtSelectedItem

Next
'If the user presses Cancel...
Else
End If
End With

'Set the object variable to Nothing.
Set fd = Nothing

End Sub

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

相关阅读

关键词不能为空
极力推荐

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