办公室-JS &VBA插件如何混合在一起 [英] Office-JS & VBA Addin How to mix together
问题描述
是否可以将 OfficeJS 命令按钮放置到像 .xlam 文件一样构建的自定义 VBA 插件面板?
* 我还是希望 VBA 和 OfficeJS 混用
Is it possible to place OfficeJS command button to Custom VBA Addin panel built like .xlam file?
* I still have hope to mix VBA and OfficeJS
推荐答案
这是未经测试的,但我相信这些方法可以解决问题:
This is untested, but I believe something along these lines will do the job:
使用<代码>CustomXMLPart.dataNodeReplaced 事件:
function addNodeReplacedEvent() {
Office.context.document.customXmlParts.getByIdAsync("vbaJSBridge", function (result) {
var xmlPart = result.value;
xmlPart.addHandlerAsync(Office.EventType.DataNodeReplaced, function (eventArgs) {
// do stuff with xmlPart
// here you should be able to receive information sent from VBA,
// and return any data necessary.
});
});
}
在 VBA 中使用:
Dim part As CustomXMLPart
' Returns a custom xml part by its ID:
Set part= ActiveDocument.CustomXMLParts.SelectByID("vbaJSBridge")
part.LoadXML("<data id="vbaJSBridge">some data</data>")
如前所述,我不确定这是否完全有效,但这是一种很好的(有点 hacky)完成这项工作的方法.或者,您可以使用 VBA 设置 HTTP 服务器,您可以将 HTTP 请求发送到 JavaScript.为此,您必须使用 Mswsock.dll 并调用 接受 方法,(我认为).
As said I am unsure whether this will work totally, but it's a nice (kinda hacky) method of doing the job. Alternatively you could set up a HTTP server with VBA, which you can send HTTP requests to the JavaScript. To do that, you'd have to use Mswsock.dll and call the accept method, (I think).
这篇关于办公室-JS &VBA插件如何混合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!