编辑:在我将特定的 Excel 文件或其窗口放在前面之前,我需要检查它是否正在运行/仍然打开。
老问题:我想将一个特定的 Excel 窗口设置在前面。
使用这个 VBScript 代码,我可以按名称激活一个 Excel 窗口。但由于打开了多个 Excel 窗口,它不再起作用。在这种情况下,它将找不到所需的窗口,并且无法检查它是否打开。所以它总是说 ExcelFileName 没有打开。
Set WshShell = WScript.CreateObject ("WScript.Shell")
if WshShell.AppActivate(ExcelFileName) = True then
wscript.echo ExcelFileName & " is opened."
WshShell.sendkeys "%x" 'in Excel 2003 this would had opened the extra-menu-droplist of the menu-bar. Now it just activates Excel.
else
wscript.echo ExcelFileName & " is not open."
End if
如何使它与多个打开的 Excel 窗口一起工作?