从.bat运行宏并打开另一个Access数据库 [英] Running Macro from .bat with another Access db open

查看:77
本文介绍了从.bat运行宏并打开另一个Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要全天定期自动运行一些Access宏,方法是安排一个批处理文件打开相关的Access db并运行该宏.

I need to run a few Access macros automatically periodically throughout the day, I do this by scheduling a batch file to open the relevant Access db and run the macro.

我遇到的问题是,如果我在另一个Access数据库上工作,因此已经打开了Access实例,则批处理文件将运行,但只会打开包含应该运行并停止的宏的数据库.因此该宏不会运行.

The problem that I am having is, if I am working on another Access database and therefore already have an instance of Access open, the batch file runs but only opens the database containing the macro that is supposed to run and stops. So the macro doesn't run.

其他人有这个问题或知道如何解决吗?

Has anyone else had this issue or know how to solve it?

任务计划程序调用的批处理文件如下所示:

The batch files that task scheduler calls look like this:

start /min "C:\Program Files\Microsoft Office 15\root\office15\MSACCESS.EXE" "Q:\TC\DNI_Updater\DNIUPDATER.accdb" /X DailyUpdate

推荐答案

使用 start/min时,我找不到一种方法来使 DailyUpdate 宏在第二个Access会话中运行打开该会话.

I could not find a way to get the DailyUpdate macro to run in the second Access session when using start /min to open that session.

我仍然不确定是否可行,但是我放弃了,转而使用 VBScript .通过这种方法,很容易启动最小化的第二个Access会话并运行宏...

I'm still unsure whether it's possible, but I gave up and switched to VBScript instead. With that approach, it's easy to start the second Access session minimized and run the macro ...

Option Explicit
Dim AccessExePath, DbPath, CmdLine, objShell
DbPath = "C:\Users\hans\Documents\test_hfu.accdb"
AccessExePath = "C:\Program Files (x86)\Microsoft Office\Office14\MSAccess.exe"
CmdLine = """" & AccessExePath & """ """ & DbPath & """" & " /X DailyUpdate"
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run CmdLine, 7 ' Minimize. The active window remains active.

如果此方法令人满意,则可以将脚本文件用作计划任务的启动程序" Action属性...

If this approach is satisfactory, you can use the script file as your scheduled task's "Start a program" Action property ...

这篇关于从.bat运行宏并打开另一个Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆