运行 application.commandbars() 外excel 或字

Run application.commandbars() outside excel or word

我正在尝试找到一种方法来 运行 一行简单的 vba 代码,例如:

application.commandbars("research").enabled = false

不打开 excel 或单词(我想为 excel 和单词引用这行代码)

我想在 vbs 中创建一个单词/excel 对象,但想不出在对象的相同上下文中使用这行代码的方法。

您应该能够像这样在 vbscript 代码中获取应用程序的现有实例:

Dim excelObj 
Set excelObj = GetObject(, "Excel.Application")

然后您可以对该对象调用任何应用程序方法:

excelObj.CommandBars("research").Enabled = False

对于 Word,执行与上述相同的操作,但使用 "Word.Application"。

注意:GetObject will throw an error if no instance of the application is currently running. In that case use CreateObject,参数相同。