如何安排宏在 Access 2007 中自动运行
例如,我希望有一个名为 Macro1 的宏每天上午 9 点运行。它可以在 Access 2007 中的 VB 代码编辑器中单独运行,但我希望它能够在不打开访问的情况下自动执行。
请注意,我不希望有任何人为干预,它需要能够自动运行,而无需有人打开 Access 来触发 autoexec 或 onload 或类似的东西。
这有可能吗?
I'd like to have a macro, called Macro1, for example, run every day at 9 AM. It works great on its own from the VB code editor in Access 2007 but I would like it to be able to execute automatically without access being open.
Please note that I don't want there to have to be any human intervention, it needs to be able to run automatically without someone opening Access to trigger autoexec or onload or something similar.
Is this at all possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 MS Access 命令行开关来运行宏。如果您在 Access 帮助中搜索“命令行”,主题“启动命令行选项”将为您提供所有命令行开关。运行宏的开关是
x macro
。因此,如果您编写宏来运行您想要的任何内容,并让它在完成后退出 Access,那么您可以创建一个命令行来完成此任务,并将其放入 Windows 任务计划程序可以执行的批处理文件中。
然而,正如我在上面的评论中所说,如果您只是运行一些查询,我认为完全绕过 Access 并直接在计划的 vbScript 中使用 DAO 来执行查询更有意义。
You can use a MS Access command line switch to run a macro. If you search for "commandline" in Access help, the topic "Startup command-line options" gives you all the commandline switches. The switch for running a macro is
x macro
.So, if you write your macro to run whatever you want and have it exit Access when it finishes, you can then create a commandline that will do the trick and put it in a batch file that the Windows Task Scheduler can execute.
However, as I said in a comment above, if you are just running some queries, I'd say it makes more sense to bypass Access entirely and use DAO directly in a scheduled vbScript to execute the queries.
您必须创建 vbscript 来运行宏,并创建批处理文件来安排 vbscript。
vb脚本代码,将其另存为schedule.vbs文件
调暗访问应用程序
设置 accessApp = createObject("Access.Application")
accessApp.OpenCurrentDataBase("完整路径\msaccessdb")
accessApp.Run“宏名称”,参数1,参数2,参数3
访问App.退出
set accessApp = Nothing
然后创建file.bat
@回声关闭
cscript Schedule.vbs
并准备好使用 Windows 任务计划程序来计划它
http://www.thewindowsclub.com/how -to-schedule-batch-file-run-automatically-windows-7
希望有帮助:D
You must create vbscript to run your macro and create a batch file to schedule your vbscript.
vbscript code, save this as schedule.vbs file
Dim accessApp
set accessApp = createObject("Access.Application")
accessApp.OpenCurrentDataBase("fullpath\msaccessdb")
accessApp.Run "Macroname",param1, param2,param3
accessApp.Quit
set accessApp = nothing
THEN create file.bat
@echo off
cscript schedule.vbs
and your ready to schedule it using the windows task scheduler
http://www.thewindowsclub.com/how-to-schedule-batch-file-run-automatically-windows-7
hope this help :D
您可以使用 Windows 任务计划程序和 VBScript 来运行代码或启动 Access。
You can use Windows Task Scheduler and VBScript to run code or start Access.