简体   繁体   English

无法从java代码运行宏

[英]Unable to run macro from java code

Below is my vb script that i want to run from my javacode. 下面是我想从我的javacode运行的vb脚本。 I am calling it using the below command filePath = "D:\\myVBS.vbs"; 我使用下面的命令filePath =“D:\\ myVBS.vbs”调用它;

    Runtime.getRuntime().exec(filePath);

i see the below error : java.io.IOException: Cannot run program "D:\\myVBS.vbs": CreateProcess error=193, %1 is not a valid Win32 application 我看到以下错误:java.io.IOException:无法运行程序“D:\\ myVBS.vbs”:CreateProcess error = 193,%1不是有效的Win32应用程序

 Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("D:\\easyAutomation2017\\GoEasy\\requiredSource\\TestData1.xlsm") objExcel.Application.Run "TestData1.xlsm!refreshXLS" objExcel.ActiveWorkbook.Close objExcel.Application.Quit WScript.Quit 

After googling i understood that this is the problem: You cannot run a shell script on Windows directly as it is no executable in the Windows sense 谷歌搜索后,我明白这是问题:你不能直接在Windows上运行shell脚本,因为它在Windows意义上是不可执行的

So how do i run it. 那么我该如何运行呢。

Please help!! 请帮忙!! Thanks 谢谢

To run a vbs script, you need to run Wscript.exe and pass the vbs file as a parameter. 要运行vbs脚本,您需要运行Wscript.exe并将vbs文件作为参数传递。

For example, 例如,

Runtime.getRuntime().exec(new String[]{"C:\\Windows\\System32\\wscript.exe", "D:\\myVBS.vbs"});

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

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