从 Excel VBA 浏览文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/221444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:00:04  来源:igfitidea点击:

Browse for a File from Excel VBA

excel-vbaexcel-2003fileopendialogvbaexcel

提问by AJ.

How can I put up a "File Open" dialog from some VBA running in Excel?

如何从在 Excel 中运行的某些 VBA 中设置“文件打开”对话框?

I'm using Excel 2003.

我正在使用 Excel 2003。

回答by tzot

You want the Application.GetOpenFilenamefunction. Copying from VBA Object Browser:

你想要这个Application.GetOpenFilename功能。从 VBA 对象浏览器复制:

Function GetOpenFilename([FileFilter], [FilterIndex], [Title], [ButtonText], [MultiSelect])
Member of Excel.Application

函数 GetOpenFilename([FileFilter], [FilterIndex], [Title], [ButtonText], [MultiSelect])
Excel.Application 的成员

回答by Galwegian

Add a reference to ComDLG32.OCX and then something like...

添加对 ComDLG32.OCX 的引用,然后类似...

Sub PromptForFile()
Dim d As New MSComDlg.CommonDialog

d.Filter = "xls"
d.Filename = "*.xls"
d.ShowOpen

Excel.Workbooks.Open d.Filename

Set d = Nothing
End Sub