从Microsoft Access运行批处理文件 [英] Run a batch file from Microsoft Access

查看:123
本文介绍了从Microsoft Access运行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从VBA运行批处理文件的技巧是什么?我正在尝试使用Shell函数调用

,但它对我不起作用。如果我

双击批处理文件或从它运行的命令行运行它。


我试过了:


RetVal = Shell(" cmd / c clean.bat",vbNormalFocus)

RetVal = Shell(" clean.bat",vbNormalFocus)

RetVal = Shell(<< full path> clean.bat",vbNormalFocus)

Call Shell ...


任何帮助都将非常感激!

解决方案

Shell" cmd /kc:\first.bat" ;,vbNormalFocus


*****

c:\ first.bat是:

@echo off

rem这是第一批文件,first.bat

echo呼叫第二个
呼叫c:\ second.bat

echo从第二个返回

*****

*****

c:\ second.bat:

@echo off

rem这是second.bat

echo运行第二批文件

*****


谢谢迈克&莱尔!我和莱尔的建议一起去了。另外一个问题。

如果批处理文件的路径在目录名中包含空格,

如何避免错误:''C:\Documents''不被识别为

内部或外部命令,可操作程序或批处理文件。


即C:\Documents and Settings\csmith\Desktop \ exxtract\clean.bat


如果路径没有空格,则有效c:\ clean.bat,但是如果

路径有空格则没有。


Shell" cmd / k" ;C:\Documents and Settings \ Lyle Fairfield \ My

Documents\Access\ first.bat"",vbNormalFocus


What''s the trick to running a batch file from VBA? I''m trying to call
it using the Shell function but it''s not working for me. If I
double-click the batch file or run it from the command line it works.

I''ve tried:

RetVal = Shell("cmd /c clean.bat", vbNormalFocus)
RetVal = Shell("clean.bat", vbNormalFocus)
RetVal = Shell("<full path>clean.bat", vbNormalFocus)
Call Shell...

Any help would be greatlyl appreciated!

解决方案

Shell "cmd /k c:\first.bat", vbNormalFocus

*****
c:\first.bat is:
@echo off
rem this is the first batch file, first.bat
echo Calling second
call c:\second.bat
echo Returned from second
*****
*****
c:\second.bat is:
@echo off
rem this is second.bat
echo Running second batch file
*****


Thanks mike & Lyle! I went with Lyle''s suggestion. One other question.
If the path to the batch file contains spaces in the directory names,
how do I avoid the error: ''C:\Documents'' is not recognized as an
internal or external command, operable program or batch file.

i.e. C:\Documents and Settings\csmith\Desktop\Extracts\clean.bat

It works if the path has no spaces e.g. c:\clean.bat, but not if the
path has spaces.


Shell "cmd /k ""C:\Documents and Settings\Lyle Fairfield\My
Documents\Access\first.bat""", vbNormalFocus


这篇关于从Microsoft Access运行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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