Office-JS & VBA Addin How to mix together

*爱你&永不变心* 提交于 2021-02-08 07:33:51

问题


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


回答1:


This is untested, but I believe something along these lines will do the job:

Use the CustomXMLPart.dataNodeReplaced event:

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.
        });
    });
}

In VBA use:

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>")

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).




回答2:


No, you cannot interact with VBA macros or COM add-ins from a web add-in. Remember that web add-ins are just like web pages, in that they are sandboxed and cannot communicate with the OS or installed programs (at least without helper or broker applications/libraries).



来源:https://stackoverflow.com/questions/45156707/office-js-vba-addin-how-to-mix-together

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!