Creating

Create a RibbonCommands folder
Create a RibbonCommands.html file in this folder
Create a RibbonCommands.js file in this folder


FunctionFile

This element specifies the file containing the javascript function that runs when a command that displays no UI, is pressed.
The javascript in the HTML file must call Office.initialize


Manifest File

<OfficeApp xsi:type="TaskPaneApp"> 
<VersionOverrides xmlns=" .../mailappversionoverrides/1.0
       xmlns: bt=".../officeappbasictypes/1.0
       xsi: type="VersionOverridesV1_0">
<Hosts>
   <Host xsi:type = "MailHost">
      <DesktopFormFactor>
         <FunctionFile resid="my-function-file-id"/>
      </DesktopFormFactor>
   </Host>
</Hosts>
<Resources>
   <bt:Urls>
      <bt:Url id="my-function-file-id"
         DefaultValue="https://localhost/RibbonCommands/RibbonCommands.html"/>
   </Urls>
</Resources>
</VersionOverrides>
</OfficeApp>

RibbonCommands.html

This only needs to contain the javascript references


<script src="../hosted/office.js" type="text/javascript"></script> 
<script src="RibbonCommands.js" type="text/javascript"></script>

RibbonCommands.js

No initialisation code is required inside the Office.Initialize property.
However this property cannot be undefined so you need to include it with any empty body.
The method that will be called when the command executes needs a parameter passed into it.
In this snippet the method (or function) is called 'OnCommandButtonClick' and the parameter is given the name 'event'.
The very last time of this function needs to be 'event.completed()'.
This indicates to the host application that the function has finished and the UI can become responsive again.

Office.initialize = function() { 
}
function onCommandButtonClick(event) {
   event.completed(); //must be called
}


© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext