如何使用vbscript获取运行excel实例的工作簿名称? [英] How to get workbook name of running excel instance using vbscript..?

查看:147
本文介绍了如何使用vbscript获取运行excel实例的工作簿名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim objXL, strMessage

On Error Resume Next

Set objXl = GetObject(, "Excel.Application")

If Not TypeName(objXL) = "Empty" then
    strMessage = "Excel Running"    
Else 
    strMessage = "Excel NOT Running"
End If

MsgBox strMessage, vbInformation, "Excel Status"

嘿,谢谢老朋友。这真的让我接近寻找的东西,更接近解决方案。
让我告诉你我的具体要求/问题:
实际上我的问题是,从Java我试图找到具有特定工作簿名称的Excel实例,但即使出现,也不会返回Excel实例。在我的情况下,我有一个Excel打开与2个工作簿Book1和Book2在其中。
当我尝试使用这些工作簿名称找到Excel时,没有给出结果。要缩小范围,这个问题仅在我的一台客户端机器上观察到。在休息机上这个相同的java代码工作正常。
这是在卸载Excel2010并安装Excel2007后开始的。

Hey thanks alot buddy. This really brings me close to what am looking for, moving much closer to the solution. Let me tell you my exact requirement/issue: Actually my issue is that, from Java I am trying to find Excel instance with a particular workbook name but am not returned an Excel instance even though it appears. In my case I have an Excel opened with 2 workbooks "Book1" and "Book2" in it. When am trying to find Excel with any of these workbook name, am given no result. To narrow down, this issue is observed only on one of my client machines. On rest machines this same java code working fine. This started happening after uninstalling Excel2010 and installing Excel2007.

所以我想要做的是,要创建一个vbscript,我可以给工作簿作为输入,它将返回我是否有这样的Excel实例运行与给定的工作簿名称。

So what I am trying to do is that, want to create one vbscript where I can give the workbookname as an input and it will return me whether there is such Excel instance running with given workbook name.

请指导我进一步创建这样的脚本,我将给工作簿名称和脚本会发现这样的Excel实例是否正在运行。即使工作簿名称作为脚本中的硬编码输入传递也不是问题。我将根据我的工作簿名称更改。

Hey please guide me further towards creating such script where I will give the workbook name and script will find whether such Excel instance is running or not. Not an issue even if workbook name is passed as an hardcoded input in script. I will alter as per my workbook name.

感谢您以前的回复,并等待这一个.. ..))

Thanks for your previous reply and awaiting for this one too.. :))

推荐答案

如果你可能有多个实例打开,而不是检测特定工作簿是否打开可以使用:

If you potentially have more than one excel instance open than to detect if a specific workbook is open you could use:


  1. 在所有实例中检查所有打开的工作簿的代码 Excel可以跨越实例进行VBA?

  2. 检测文件是否已被使用。有关 Sid的建议检查Excel工作簿是否已经打开

  3. Doug的建议使用 GetObject 附加到您知道工作簿名称的主机实例。根据 Microsoft支持文章,您可以使用 Set xlApp = GetObject( YourExcelName)。应用程序来检测YourExcelName是否在任何实例中打开

  1. This code to examine all open workbooks in all instances Can VBA Reach Across Instances of Excel?
  2. Detect if the file is already in use. See Sid's suggestion from Detect whether Excel workbook is already open
  3. Doug's suggestion to use GetObject to attach to a host instance where you know the workbook name. As per the Microsoft Support article you can use Set xlApp = GetObject("YourExcelName").Application to detect if "YourExcelName" is open in any instance

在问题中您最初询问的是,以下代码使用 GetObject 来检测是否有任何实例是打开的,如果有一个 ActiveWorkbook 那个名字呢从您编辑的问题,我上面的三个链接比这个代码更相关。

In the question that you initially asked, the code below uses GetObject to detect whether any instance is open, and if there is an ActiveWorkbook and what that name ie. From your edited question my three links above are more relevant than this code.

Dim objXL, WB, strMessage
On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
Set WB = objXL.ActiveWorkbook
On Error GoTo 0
If Not TypeName(objXL) = "Empty" Then
    If Not TypeName(WB) = "Nothing" Then
    strMessage = "Excel Running - " & objXL.ActiveWorkbook.Name & " is active"
    Else
    strMessage = "Excel Running - no workbooks open"
    End If
Else
    strMessage = "Excel NOT Running"
End If
MsgBox strMessage, vbInformation, "Excel Status"""

这篇关于如何使用vbscript获取运行excel实例的工作簿名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆