Ruby Office Automation - 无法让事件处理程序在 MSWord 中工作
Ruby 版本 1.9.1p430 在 Office 2010 的 W7 上运行。
我试图捕获 DocumentBeforeClose 事件,但我什至无法接近让它工作!
我遵循了一些使用 Excel 处理 SheetSelectionChange 的示例。它工作没有任何问题。
我想使用相同的过程来处理上述 Word 事件。
我的代码在 WIN32OLE_EVENT.new 语句处失败。这是我正在使用的:
require 'win32ole'
wd = WIN32OLE.connect('Word.Application')
wd.visible = true
doc = wd.Documents.Add
ev = WIN32OLE_EVENT.new(doc, 'ApplicationEvents4')
我得到的错误是:
ev = WIN32OLE_EVENT.new(doc, 'ApplicationEvents4')
RuntimeError: failed to query IConnectionPoint
HRESULT error code:0x80040200
我在 WIN32OLD_EVENT 语句中广泛查找了接收器名称的正确内容,但这是我想出的最好的内容,它是显然不正确!
如果有人能指出我正确的方向,我将不胜感激。我很想知道是否有人成功处理 Ruby 中的 Word 事件。
Ruby version 1.9.1p430 running on W7 with Office 2010.
I am trying to catch the DocumentBeforeClose event but I cannot even get close to get it to work!
I have followed some examples using Excel where the SheetSelectionChange is handled. It works without any problem.
Using the same process, I wanted to handle the above Word event.
My code fails at the WIN32OLE_EVENT.new statement. Here is what I am using:
require 'win32ole'
wd = WIN32OLE.connect('Word.Application')
wd.visible = true
doc = wd.Documents.Add
ev = WIN32OLE_EVENT.new(doc, 'ApplicationEvents4')
The error I get is:
ev = WIN32OLE_EVENT.new(doc, 'ApplicationEvents4')
RuntimeError: failed to query IConnectionPoint
HRESULT error code:0x80040200
I have looked extensively for the correct content for the name of the sink in the WIN32OLD_EVENT
statement but this is the best I have come up with and it's obviously incorrect!
I would be most grateful if someone can point me in the right direction. I would be interested to hear if anyone has managed to succesfully handle Word events from Ruby.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您应该在 WIN32OLE_EVENT 调用中使用 Word 对象而不是 doc 对象,因为“ApplicationEvents4”与 Word.Application 相关。
附注
不要忘记消息循环
I think you should use Word object instead of doc object in WIN32OLE_EVENT call, because of 'ApplicationEvents4' relates to Word.Application.
PS
Don't forget about message loop