如何在MS Access中集成DOS批处理文件? [英] How can I integrate DOS batch files in MS Access?

查看:112
本文介绍了如何在MS Access中集成DOS批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Access宏将整个excel文件(不仅仅是一系列数据)从一个目录传输到另一个目录,因为我想在Access中将它们与我的其他宏一起散布。我想运行一个将调用其他宏的宏。所以我想我需要弄清楚如何从Access运行DOS批处理文件并将它们合并到我的Access dB中。我想我必须使用Shell / VBA。


例如,如果我的批处理文件是Transfer01in.bat,Access中的代码可能看起来像

调用Shell(Environ $(" COMSPEC")&" /cc:\Transfer01in.bat" ;,vbNormalFocus)


我的批处理文件Transfer01in.bat将包含

copy" C:\ CD BI Model \2010 07 \ *。*" C:\ CD BI Model \Version E \ *。* / y


(Environ $(" COMSPEC")返回计算机上Command.com的路径,/ c参数确保Dos窗口自动关闭当批处理文件完成执行时。


我需要帮助将它全部集成到我的Access数据库文件中。

解决方案

( COMSPEC)&" /cc:\Transfer01in.bat" ;,vbNormalFocus)


我的批处理文件Transfer01in.bat将包含

copy" C:\ CD BI Model \2010 07 \ *。*" C:\ CD BI Model \Version E \ *。* / y


(Environ


(" COMSPEC")返回机器上Command.com的路径和/ c。参数确保在批处理文件完成执行时自动关闭Dos窗口。


我需要帮助将它全部集成到我的Access数据库文件中。


听起来你非常接近你的解决方案。


你可以让Access Macro运行一个函数,其中包含执行目录复制所需的任何代码。


宏操作是''RunCode''。


如果你的代码包含对内置函数的单个函数调用,那就放一下在''Function Name''参数中。


如果您需要自定义函数,则可以将其放在单独的模块中,从而可以更轻松地复制到新的Access数据库。

I need to transfer entire excel files (not just a range of data) from one directory to another using an Access Macro because I want to intersperse them with my other macros in Access. I want to run one macro that will call other macros. So I am thinking I need to figure out how to run DOS Batch files from Access and incorporate them in my Access dB. I think I have to use Shell / VBA.

If, for example, my batch file was Transfer01in.bat, the code in Access might look like
call Shell ( Environ$ ( "COMSPEC" ) & " /c c:\Transfer01in.bat", vbNormalFocus)

And my batch file, Transfer01in.bat, would contain
copy "C:\CD BI Model\2010 07\*.*" "C:\CD BI Model\Version E\*.*" /y

(Environ$("COMSPEC") returns the path to Command.com on the machine and the "/c" argument makes sure that the Dos window is automatically closed when the batch file finishes executing.

I need help to integrate it all into my Access database file.

解决方案

( "COMSPEC" ) & " /c c:\Transfer01in.bat", vbNormalFocus)

And my batch file, Transfer01in.bat, would contain
copy "C:\CD BI Model\2010 07\*.*" "C:\CD BI Model\Version E\*.*" /y

(Environ


("COMSPEC") returns the path to Command.com on the machine and the "/c" argument makes sure that the Dos window is automatically closed when the batch file finishes executing.

I need help to integrate it all into my Access database file.


It sounds like you are very close to your solution.

You can make an Access Macro run a function that contains whatever code is needed to perform the directory copy.

The macro action is ''RunCode''.

If your code consists of a single function call to a built-in function, just put it in the ''Function Name'' argument.

If you need a custom function then you could place it in a separate module, making it easier to copy over to a new Access database.


这篇关于如何在MS Access中集成DOS批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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