简体   繁体   English

使用VBScript检查Excel工作簿是否已打开

[英]Check if Excel workbook is open using VBScript

I have a vbs script which writes to an Excel spreadsheet. 我有一个写入Excel电子表格的vbs脚本。 To be able to save the spreadsheet I need to ensure that it is not already open. 为了能够保存电子表格,我需要确保它尚未打开。
Can someone suggest the best way to do this? 有人可以建议最好的方法吗?

Some research: 有些研究:

  • I tried to create a Word Tasks objects to show me all running processes, but on Windows 7 it only tells me whether Excel is running or not. 我尝试创建Word Tasks对象以向我显示所有正在运行的进程,但在Windows 7上它只告诉我Excel是否正在运行。
  • Creating an Excel.Application object does not give me access to all running instances of Excel. 创建Excel.Application对象不允许我访问所有正在运行的Excel实例。
  • I thought about opening the spreadsheet for writing but the only way I can think of doing this is with the File System Object OpenTextFile method which does not seem to be the correct approach as the Excel file is a binary. 我考虑打开电子表格进行编写,但我能想到的唯一方法是使用文件系统对象OpenTextFile方法,因为Excel文件是二进制文件,所以这似乎不是正确的方法。

Any other ideas? 还有其他想法吗?

Since the Excel.Application object doesn't give you access to all instances of Excel, what about using a simple error trap? 由于Excel.Application对象不允许您访问Excel的所有实例,因此使用简单的错误陷阱呢? ie. 即。 if it is unable to save the file, throw a warning message, save as another file name, etc. 如果无法保存文件,则抛出警告消息,另存为其他文件名等。

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

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