0
votes

What I am going to do is to add a custom command button to execute a JavaScript function in Microsoft Office(Word or Excel).

Specifically, I need to build a command to copy the link of an opened document file(Word/Excel).

I was able to build an add-in with taskpane using Office Add-in like the following image.

enter image description here

But can I build a command button without taskpane?

Ideally, a command button should copy the link of an opened document file and show success dialog.

The command button also should be used for a registered app in Azure Active Directory.

UPDATE

Regarding the documentation, it says I could use action xsi:type as ExecuteFunction rather than using ShowTaskpane, but it is not working as well.

<?xml version="1.0" encoding="utf-8"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
...
  <DefaultSettings>
    <SourceLocation DefaultValue="https://localhost:3000/commands.js" />
  </DefaultSettings>
...

      <Host xsi:type="Document">
        <!-- Form factor. Currenly only DesktopFormFactor is supported. We will add TabletFormFactor and PhoneFormFactor in the future-->
        <DesktopFormFactor>
          ...
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <!--Use OfficeTab to extend an existing Tab. Use CustomTab to create a new tab -->
            <!-- Documentation includes all the IDs currently tested to work -->
            <CustomTab id="Contoso.Tab1">
                ...
                  <Action xsi:type="ExecuteFunction">
                  <!--Name of the function to call. This function needs to exist in the global DOM namespace of the function file-->
                    <FunctionName>writeText</FunctionName>
                  </Action>
                </Control>
...

Is this available?

2

2 Answers

1
votes

Currently, Excel does not support linking up buttons or shapes that live on the worksheet grid with Javascript functions. You will need to use the taskpane for these.

0
votes

The problem was because I was using old version of Office. I tried to build add-in using Office 2016, all went bad. But when I tried using the latest version of Office, everything worked for me.