简体   繁体   English

使用批处理文件打开时运行 Access 宏

[英]Running Access Macro whilst open using Batch file

I have a batch file which contains a path to the access database.我有一个批处理文件,其中包含访问数据库的路径。 When clicked it opens up the desired database however I want the batch file to run the macro.单击它会打开所需的数据库,但是我希望批处理文件运行宏。

I can do this by creating a AutoExec macro to run when you open up the database but I also want the macro to run whilst the database is running.我可以通过创建一个 AutoExec 宏在您打开数据库时运行来做到这一点,但我也希望该宏在数据库运行时运行。

Here is what I have on my batch file at the moment:这是我目前在批处理文件中的内容:

echo off
start "C:\Program Files (x86)\Microsoft Office\Office\MSACCESS.EXE" "S:\DB NEW\Report.accdb"

How do I do this?我该怎么做呢?

You can use the /x "macroname" command line indicator to run a macro (not a VBA sub or function, a macro):您可以使用 /x "macroname" 命令行指示器来运行宏(不是 VBA 子或函数,宏):

echo off
start "C:\Program Files (x86)\Microsoft Office\Office\MSACCESS.EXE" "S:\DB NEW\Report.accdb" /x MyMacroName

Read more: Command-line switches for office .阅读更多: office 的命令行开关

Alternatively, you can read commands passed using the /cmd switch from VBA.或者,您可以从 VBA 读取使用 /cmd 开关传递的命令。 You could use an auto-starting form that reads a command and executes a VBA function on load, or a predeclared class that reads and executes the command on initialize.您可以使用读取命令并在加载时执行 VBA 函数的自动启动表单,或者使用在初始化时读取和执行命令的预声明类。

For more advanced functionality, I recommend switching to either PowerShell or VBScript.对于更高级的功能,我建议切换到 PowerShell 或 VBScript。 That way you can hook into running Access Application objects and get them to execute code.通过这种方式,您可以连接到正在运行的 Access Application 对象并让它们执行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM