问题
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