vba 如何通过在文件对话框中选择文件将文件导入 MDB?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5308607/
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
How can I import a file to a MDB by selecting a file in a File Dialog Box?
提问by lamwaiman1988
I am new to vb/vba.....don't quite know about them.....
My boss ask me to develop a ms access MDB with some functions, but then first I need to create some interface for the user to import the source file for the table in the MDB.
我是 vb/vba 的新手..... 不太了解它们.....
我的老板让我开发一个具有一些功能的 ms access MDB,但首先我需要为用户创建一些界面导入 MDB 中表的源文件。
I would like to have button "Browse", when the user press it, a file dialog box pop up and the user select the input file, then the program will use this input file and import it's data into my table, Any idea?
我想要“浏览”按钮,当用户按下它时,会弹出一个文件对话框,用户选择输入文件,然后程序将使用这个输入文件并将其数据导入我的表中,知道吗?
I am using ms access 2000 and assume the user use ms access 2000 too.
我正在使用 ms access 2000 并假设用户也使用 ms access 2000。
Thanks.
谢谢。
回答by TheOtherTimDuncan
Take a look at the FileDialog object. You'll need to add the Microsoft Office Object Library to your references.
看一看 FileDialog 对象。您需要将 Microsoft Office 对象库添加到您的引用中。
Dim Filename As String Dim df As FileDialog
Dim Filename As String Dim df As FileDialog
Set df = Application.FileDialog(msoFileDialogOpen)
设置 df = Application.FileDialog(msoFileDialogOpen)
With df
与 df
.AllowMultiSelect = False .Filters.Clear .Filters.Add "Access files", "*.mdb" .InitialFileName = "C:\" .Title = "Open File"
.AllowMultiSelect = False .Filters.Clear .Filters.Add "Access files", "*.mdb" .InitialFileName = "C:\" .Title = "Open File"
If .Show = True Then
Filename = .SelectedItems(0)
End If
If .Show = True Then Filename = .SelectedItems(0)
End If
End With
结束于