OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
674 stars 95 forks source link

Trigger VBA commands on open via Office.js #357

Closed MortenHaldMortensen closed 5 years ago

MortenHaldMortensen commented 5 years ago

Expected Behavior

On Windows autoopen/autonew commands kicks in when opening a document using https://docs.microsoft.com/en-us/javascript/api/word/word.application?view=office-js#createdocument-base64file-.

This would be expected behavior on MAC as well.

Current Behavior

Nothing happens...

Steps to Reproduce, or Live Example

Create a "hello world" box that should run on autoopen/autonew. Confirm that it runs in Windows. It will not run on the MAC.

Context

I am trying to activate some legacy code when opening a new document using office.js

Your Environment

MAC, Office 365.

JuaneloJuanelo commented 5 years ago

First of all a quick clarification, since this question is a bit misleading: It depends on your trust center settings whether if you will be able to execute a macro in Windows. where by default macros are disabled and users will be prompted if they call the createWorkbook API. So for the vast majority of users they will be prompted if you intend to run a Macro.

The feature was disabled in Mac and most probably will also be disabled in Windows soon (i.e. you will not be able to use workbooks with macros with this method) , the main reason is the lack of multiplatform support for the scenario (i.e. Excel Online and iOS).

MortenHaldMortensen commented 5 years ago

Hi @JuaneloJuanelo

Thank you for the response on this. I accept that it is closed and have found a work-around.

I was confused that it did work on Windows and that it worked on the Mac when opening a document (linked to a template) not using office.js. Also do note that the "issue" was with Word and not Excel. I will note that this is a feature that is discontinued purposely.

JuaneloJuanelo commented 5 years ago

thanks.. whats the workaround? also this info applies to Excel, Word and PPT, good catch!

MortenHaldMortensen commented 5 years ago

The workaround was a completely different approach to support the legacy VBA features in a transitioning period where office.js is used for creating and legacy VBA can run until everything can be transitioned.

921kiyo commented 1 year ago

@MortenHaldMortensen Could you tell me the workaround? I also have to run legacy VBA code from office.js, and am looking for a solution.