vba 如何在 Access 2007 中的宏中自动保存导入?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7230931/
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 do I automate a saved import in a macro in Access 2007?
提问by dany
I have created a macro to run a saved import (a file imported from Excel into Access 2007). When I run the macro, the saved import runs and the following happens:
我创建了一个宏来运行保存的导入(从 Excel 导入到 Access 2007 的文件)。当我运行宏时,保存的导入运行并发生以下情况:
- A "Manage Data Tasks" window pops up.
- I have to choose from the following options:
Run
,Create Outlook Task...
,Delete
, andClose
. - If I select
Run
, the next pop-up asks, "Overwrite existing table or query?" - I have to choose:
Yes
orNo
. - Another window pops up and says, "All objects were imported successfully."
- I have to click the
OK
button. - I have to click the
Clos
ebutton on the "Manage Data Tasks" Window.
- 弹出“管理数据任务”窗口。
- 我从以下选项中进行选择:
Run
,Create Outlook Task...
,Delete
,和Close
。 - 如果我选择
Run
,下一个弹出窗口会询问“覆盖现有表或查询?” - 我必须选择:
Yes
或No
。 - 另一个窗口弹出并显示“所有对象均已成功导入”。
- 我必须点击
OK
按钮。 - 我必须单击“管理数据任务”窗口上的
Clos
e按钮。
Is there any way that I can automate all these button clicks if they are always going to be the same? (The bold faced buttons are the ones that I'll always be clicking.)
如果它们总是相同,有什么方法可以使所有这些按钮点击自动化?(粗体按钮是我会一直点击的按钮。)
回答by Conrad Frix
If you use the DoCmd.RunSavedImportExport Methodyou won't have to interact with the Manage Data Tasks dialog at all.
如果您使用DoCmd.RunSavedImportExport 方法,则根本不必与“管理数据任务”对话框进行交互。
DoCmd.RunSavedImportExport "YourSavedImportName"
You will however have to deal with the possible errors that get raised. For example if your source file is unavailable you will get an error like
但是,您将不得不处理可能引发的错误。例如,如果您的源文件不可用,您将收到类似的错误
Run-time error '3011':
The Microsoft Office Access database engine could not find the object 'Sheet1'. Make sure the object exists and the you spell its name and the path correctly.
运行时错误“3011”:
Microsoft Office Access 数据库引擎找不到对象“Sheet1”。确保该对象存在并且您正确拼写了它的名称和路径。
回答by tired
This may be too simple, but can you use the Setwarnings:off command in your macro before you import.
这可能太简单了,但是您可以在导入之前在宏中使用 Setwarnings:off 命令吗?
Now I would like to see the macro to automate the import
现在我想看到自动导入的宏