简体   繁体   English

如何在Excel中按住VB SCRIPT调用jar文件并按住屏幕

[英]How to call jar file using VB SCRIPT in excel and hold screen

I want to call a java jar file using vb script in excel. 我想在Excel中使用vb脚本调用Java jar文件。 My file format is "xlsm" where is my vb script code. 我的文件格式为“ xlsm”,这是我的vb脚本代码。

When i execute my code, then console comes and go, I do not what is written on console. 当我执行代码时,控制台来来去去,我不写控制台上的内容。 please have a look at code 请看一下代码

Public Function RunProgram( _
program As String, _
Optional command As String = "" _
) As WshExec
Dim wsh As New WshShell
Dim exec As WshExec
Dim oShell
Application.ScreenUpdating = False
Set exec = wsh.exec(program)
Call exec.StdIn.WriteLine(command)
 Set RunProgram = exec
'Application.ScreenUpdating = True
End Function
Public Function evenOdd1(Number As Double) As Double
Call Run
End Function

Public Sub Run()
Dim program As WshExec
Set program = RunProgram("java -jar G:\\excel\\MyTest.jar""Margus") 
'Debug.Print "STDOUT: " & program.StdOut.ReadAll
End Sub

I have tried Application.ScreenUpdating, Application.visible to hold the screen but unable to hold console.. Please help me 我尝试了Application.ScreenUpdating,Application.visible来保存屏幕,但无法保存控制台。

When i execute my code, then console comes and go, 当我执行代码时,控制台就来了,

Do you mean that a console window (basically cmd.exe ) pops up on the screen and then disappears? 您是说控制台窗口(基本上是cmd.exe )在屏幕上弹出然后消失了吗? If that's what's going on, then either (a) there's a problem with your command (bad syntax, can't find java , etc.) so the system exits immediately without running your command; 如果是这样,那么(a)您的命令存在问题(语法错误,找不到java等),因此系统在不运行您的命令的情况下立即退出; (b) the system ran the command, but java didn't understand the command's arguments, and is exiting immediately; (b)系统运行了该命令,但是java不理解该命令的参数,并立即退出; or (c) your Java program runs properly and exits immediately (this is unlikely -- Java takes at least a few hundred milliseconds to load). 或(c)您的Java程序正常运行并立即退出(这不太可能-Java至少需要花费几百毫秒来加载)。

To determine which is the problem, you might try using this as your command (instead of whatever you're generating): 要确定是哪个问题,您可以尝试使用以下命令(而不是生成的命令):

ping 1.1.1.1 -n 1 -w 5000

That will open a command prompt (aka "console window"), try to ping the (invalid) IP address 1.1.1.1 , and wait 5 seconds for a response. 这将打开命令提示符(又名“控制台窗口”),尝试ping(无效)IP地址1.1.1.1 ,然后等待5秒钟以获取响应。 The command should stay up for 5 seconds while it waits for a response. 该命令在等待响应时应保持5秒钟的时间。

If the command prompt does stay up for 5 seconds, then you've confirmed that the problem is the command you're trying to run. 如果命令提示符确实停留了5秒钟,则表明您已确认问题是您要尝试运行的命令。 Try printing the command you're trying to run to a VB console and running it in cmd.exe to see what's wrong. 尝试将要运行的命令打印到VB控制台,然后在cmd.exe运行它,以查看出了什么问题。

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

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