专门做任务的网站,广告软文外链平台,手机之家报价,荆门网站开发有哪些excel_vba可实现弹窗进行人机交互#xff0c;本案例实现弹窗选择需要打开的excel文件#xff0c;选择文件后打开该文件#xff0c;然后弹窗提示该文件另存为路径及目录#xff0c;代码如下#xff1a;
Sub 打开文件对话框()
On Error Resume Next
With Application.FileD… excel_vba可实现弹窗进行人机交互本案例实现弹窗选择需要打开的excel文件选择文件后打开该文件然后弹窗提示该文件另存为路径及目录代码如下
Sub 打开文件对话框()
On Error Resume Next
With Application.FileDialog(msoFileDialogOpen).Title 请选择你要的文件.AllowMultiSelect True.InitialFileName C:\Users\Administrator\Desktop\.Filters.Clear.Filters.Add excel files, *.xls,*.xlsx,*.dwgIf .Show True ThenSet gof .SelectedItems.ExecuteElse: Exit SubEnd If
End With
ActiveSheet.Cells(11, 5).Value gof.Item(1)
MsgBox 另存为
With Application.FileDialog(msoFileDialogSaveAs).Title 另存为.AllowMultiSelect True.InitialFileName C:\Users\Administrator\Desktop\If .Show True ThenSet gof .SelectedItems.ExecuteElse: Exit SubEnd If
End With
ActiveWorkbook.Close
End Sub
Application.FileDialog 属性 (Excel)
本文内容
语法参数备注示例
返回一个 FileDialog 对象它表示文件对话框的实例。
语法
expression.FileDialog (fileDialogType)
expression表示 Application 对象的变量。
参数
展开表
名称必需/可选数据类型说明fileDialogType必需MsoFileDialogType文件对话框的类型。
备注
MsoFileDialogType 可为下述常量之一
msoFileDialogFilePicker。 允许用户选择文件。msoFileDialogFolderPicker。 允许用户选择文件夹。msoFileDialogOpen。 允许用户打开文件。msoFileDialogSaveAs。 允许用户保存文件。
示例
在此示例中Microsoft Excel 打开文件对话框允许用户选择一个或多个文件。 选择这些文件后Excel 会在单独的消息中显示每个文件的路径。
VB复制
Sub UseFileDialogOpen() Dim lngCount As Long Open the file dialog With Application.FileDialog(msoFileDialogOpen) .AllowMultiSelect True .Show Display paths of each file selected For lngCount 1 To .SelectedItems.Count MsgBox .SelectedItems(lngCount) Next lngCount End With End Sub