如何只有在Excel工作簿是打开使用VBScript运行宏?
世界!
我想在我的工作自动完成报表任务,我有以下情况:
I am trying to automate a report task at my job and I have the following situation:
我需要通过使用脚本的工作簿执行宏。我试着写一个VBScript来完成这项工作,这是它的显著部分:
I need to execute a macro on a workbook by using a script. I tried to write a vbscript to do the job, and this is the significant part of it:
Set objWbk = GetObject("***Path***\test.xlsm")
objWbk.Application.Run "test.xlsm!test"
WScript.Quit
宏完美运行。我真正的问题是,我只希望做的报告只有在工作簿是开放的。
The macro runs perfectly. My real problem is that I only want to do the report only if the workbook is open.
有没有一种方法(在VBS或VBA),以确定是否该工作簿是打开的? (顺便说一句,它位于另一台计算机上我的网络上)
Is there a way (in vbs or vba) to determine if that workbook is open ? (by the way, it is located on another computer on my network)
由于要运行宏,只有当工作簿已经打开,这样的事情可能工作:
Since you want to run the macro only when the workbook is already opened, something like this might work:
wbName = "test.xlsm"
wbFullName = "***Path***\" & wbName
Set xl = GetObject(, "Excel.Application")
For Each wb In xl.Workbooks
If LCase(wb.Path & "\" & wb.Name) = wbFullName Then
wb.Application.Run wbName & "!test"
End If
Next