ShellExecute是否可以发送类似于Vba中Shell的命令

问题描述 投票:0回答:1

我在宏中包含此Shell调用,当Excel单元格选择更改时,该宏会被触发。

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A2000")) Is Nothing Then
Shell "C:\Program Files\CTrading\QuantShare\QuantShare.exe TaskManager ChangeSymbol newsymbol:" & ActiveCell.Value, 1
Cancel = True
End If
End Sub

但是Shell调用不适用于我系统中的某些程序(Windows 10 Pro,版本1909,内部版本18363.476,MS Office 2013和Office 365)。大多数情况下,Windows 10问题无法解决。我可以使用ShellExecute来实现吗?还是ShellExecute仅用于打开具有特定exe的文件而不能在目标程序内部发送其他命令?

基本上,此代码位于Quantshare.exe当前打开的实例中--->激活其中一个名为TaskManager的插件,并执行一个名为ChangeSymbol的脚本。该脚本中的变量将使用活动Excel单元格的内容。在Windows Run或CMD中,它执行所有操作。

excel vba shell shellexecute
1个回答
0
投票

最后,我可以按如下方式使用ShellExecute:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A2000")) Is Nothing Then
Set objShell = CreateObject("Shell.Application")
para = "TaskManager ChangeSymbol newsymbol:" & ActiveCell.Value
objShell.ShellExecute "C:\Program Files\CTrading\QuantShare\QuantShare.exe", para, "", "open", 1
Set objShell = Nothing
Cancel = True
End If
End Sub

现在,Vba终于可以完成这项工作,但是唯一的效率低下是它显示了UAC用于打开应用程序,而Shell不像Shell,它可以直接实现命令而无需任何程序打开提示。我可以通过将UAC降低为“从不通知”来抑制它。另一个选择是使用Task Scheduler,在其中定义此特定应用程序以进行通知。但是当我放置快捷方式文件名和路径时,它没有发生。

如何使ShellExecute不打开单独的实例?

© www.soinside.com 2019 - 2024. All rights reserved.