简体   繁体   English

在Excel 2010 VBA中调用Shell命令

[英]Call shell command in Excel 2010 VBA

When I call a shell command in vba , the program opens as does the command prompt but nothing happens and no results are obtained. 当我在vba调用shell命令时,程序会像命令提示符一样打开,但是什么也没有发生,也没有结果。 I can not seem to figure it out and need some help please. 我似乎无法弄清楚,需要帮助。

Command that works 有效的命令

C:\Program Files\BioDiscovery\ImaGene 9.0>ImaGene.exe -batch "C:\Users\cmccabe\Desktop\EmArray\Design\test_11_19_2015.bch"

My attempt in excel 2010 using VBA (which opens the program and command prompt, but does not execute the command). 我在Excel 2010中使用VBA的尝试(打开程序和命令提示符,但不执行命令)。

Dim Par As String

Par = "dir c:\Program Files\BioDiscovery\ImaGene 9.0\ImaGene.exe -batch "C:\Users\cmccabe\Desktop\EmArray\Design\imagene.bch"
Call Shell("C:\WINDOWS\system32\cmd.exe /c " & Par, 1)
MsgBox ("ImaGene analysis complete")

May not be the best answer but the below solution works for me for similar situation. 可能不是最佳答案,但以下解决方案对我来说适用于类似情况。

open a notepad "c:\\Program Files\\BioDiscovery\\ImaGene 9.0\\ImaGene.exe" -batch "C:\\Users\\cmccabe\\Desktop\\EmArray\\Design\\imagene.bch" save as say "test.bat" 打开记事本“ c:\\ Program Files \\ BioDiscovery \\ ImaGene 9.0 \\ ImaGene.exe”-批处理“ C:\\ Users \\ cmccabe \\ Desktop \\ EmArray \\ Design \\ imagene.bch”,另存为“ test.bat”

In excel call this .bat file Dim wshell As Object 在excel中将此.bat文件称为Dim wshell As Object

Set wshell = CreateObject("wscript.shell") wshell.Run Chr(34) & "full path\\test.bat" 设置wshell = CreateObject(“ wscript.shell”)wshell。运行Chr(34)和“完整路径\\ test.bat”

Hope this helps. 希望这可以帮助。

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

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