如何用VBA打开选择文件和选择路径的对话框

如何用VBA打开选择文件和选择路径的对话框,第1张

'在文件对话框对中返回选择一个文件夹的路径.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'--------------------------------------------------------'在文件对话框对中,选择一个文件。

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11968249.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存