3

Is there a way to fire a function when clicking on a contentControl in Office-js?

I am writing an add-on for MS Word, and I have inserted content controls, that will be associated with a list in my add-in. I need to fire a function when clicking on the content control, so I can scroll to the item in the list and highlight it.

I have found the "Document.ContentControlOnEnter event (Word)" which seems to be what I am looking for, but I cannot understand how to attach an event-listener that listens to this event.

I am writing the plugin in typescript react.

4
  • 1
    The Document.ContentControlOnEnter event is part of the VBA APIs, not the Office-js APIs, so it is unclear whether you are making a VBA add-in or a web add-in. Please clarify. Commented Mar 23, 2022 at 17:42
  • Thank you! No I intend to write an Office-js API add-in. I was just confused in the documentation. Do you know of any way at all that I can run a function when a user enters or clicks a content control? Commented Mar 23, 2022 at 22:02
  • Are you looking for this? learn.microsoft.com/en-us/javascript/api/word/… According to this page there are three events: onDataChanged, onDeleted and onSelectionChanged. Would you be able to use these events to fire your function? Commented Mar 24, 2022 at 12:47
  • Yes, I have also seen that. Two issues, first they are listed as preview and should not be used in production, second I cannot figure out how to listen to those events. I tried listening to thos events in this event handler, but it was not allowed: Office.context.document.addHandlerAsync(Office.EventType.DocumentSelectionChanged, handler); Commented Mar 24, 2022 at 13:33

1 Answer 1

1

Word web add-ins don't provide anything for that.

UPD: You may be interested in the onSelectionChanged event which is fired when selection within the content control is changed. Note, this event is provided as in preview and not availble in a production environment.

Sign up to request clarification or add additional context in comments.

2 Comments

I have seen other add-ins that has this functionality. If I click on a content control the add-in is updated to show the information of the clicked content control. How do others do it if it does not exist? Is this possible if I build my add-in through some other technology?
You may be interested in the onSelectionChanged event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.