Subscribe to Word Events - ms-word

Is there way to subscribe to word events to call office js functions, primarily to functions like cut paste undo etc. Am i missing something. I have gone thru the documentation and found some events like DocumentSelectionChangedEvent , BindingDataChangedEventArgs.
Thanks
Manoj

Related

Office-JS Word Add-in Document-to-sidebar communication

I'm working on a taskpane add-in for Microsoft Word. So far, I'm able to place comments inside the Docx coming from the sidebar by abusing the OOXML insertion function.
I'm wondering if it's possible to monitor what the end user does with the comment.Is the commented deleted or accepted by the user? It is also significant to monitor the context of the comment - is that changed significantly?
I've considered the following approaches:
Create a ContentControl for the context of the comment to which events can be hooked that check for selection and changes. The downside here is that these ContentControl affect the UI in word and are probably not understood by our end-user. Are there more 'background' ways to do this without affecting the UI too much?
Create an interaction Hyperlink in the comment. I'm not sure if we can 'catch' this as an event or attach a JavaScript hook to this that actually makes it to the add-in?
Poll the document at set intervals to determine if something has happened to the comment or the context of the comment. I'm not sure what the correct hooks for this would be, and how to accurately localize all the changes across the document.
Is there an approach that I missed?
I'm aware that adding these comments is on the roadmap for the office-js, but this has been the case for a couple of years so I'm not sure what the timeframe is for this.
Edit
#Cindy thanks for taking the time to respond! With your help I've been able to get a functioning proof of concept using the hidden Content Control as a prepended OOXML snippet for the comment (So basically approach 1 combined with the OOXML insertion).
I can now capture some of the interaction by adding a binding to the content control and using the EventType.BindingDataChanged, something like this:
Office.context.document.bindings.addFromNamedItemAsync("MyContentControlTest", "text", {}, function (result) {
if (result.status == "succeeded") {
result.value.addHandlerAsync (
Office.EventType.BindingSelectionChanged, function()
{console.log("Don't touch me");}
)
})
})
It still feels a bit circumspect to attach a binding over a ContentControl, but I have not been able to add event listeners directly to the ContentControl. Given a named Content Control (MyContentControlTest) how could I attach an event like the OnDataChanged? And if i read correctly, this last feature is still in Preview, is there a way to find out what the expected release is?

Office JavaScript API: highlighting text in a document

I'm working on a side project using the Microsoft Office JavaScript APIs. I have been relying on the documentation to find my way around, but I've hit a wall trying to find something in the docs (perhaps it isn't there because it doesn't exist).
Recently I attempting to implement some functionality to highlight some text within a Word document. I don't want to modify the document, mind you; in other words I would rather not use something like ContentControl.insertHtml as that would change the actual content. What I want is to make the text temporarily highlighted (e.g., until the user clicks a "Cancel" button), much like what you see when you perform a search with Ctrl+F (and text matching your search is highlighted in yellow).
Is this possible using the Office JavaScript APIs?
Try getting a reference to the Range object and then setting Range.font.highlightcolor. Have a handler for the Cancel button click event that reverses the color change.
Here is a sample application that uses font.highlightcolor from the Office Javascript API. https://github.com/OfficeDev/Word-Add-in-JS-Redact/

Access 2016: Alt+Tab...toggle between open forms by using Alt+Tab

I've got roughly 10 forms of which I need 2 or 3 open at same time. (BTW: the forms are linked to separate tables) I know I can open multiple forms but I need to be able to toggle between the open forms using "Alt+Tab" ..... anyone know if this is possible? Thank you in advance... Tjay
BTW: I posted on Stackoverflow as well and got some great tips but didn't accomplish what I was needing.
As mentioned in your other post (Old Post):
This cannot be done with use of Alt+Tab, you would need to use the MS Access shortcut setup in the design of the program CTRL+F6
It is not possible to override the Alt+Tab Windows function programmatically to achieve the results you are looking for.
Here's a simple question for you though; why would you "need to be able to toggle between the open forms using Alt+Tab"? Is there some specific reason you need Alt+Tab to accomplish your goal? Perhaps what you need can be accomplished through some other means.
For instance, you can setup events such as SetFocus for specific forms after certain events have been finalized, while not an Alt+Tab to a form, it accomplishes a similiar end result.

How to keep Google Assistant Behavior but also trigger IFTTT

I know you can make custom Google Assistant triggers that will invoke IFTTT. But I want to make a custom trigger that will do something but /also/ keep the default Google Assistant behavior. Is there a way to do this?
Description of my actual goal: I speak German as much as possible at home with my daughter. But there are times where I don't know a word, so I can say "OK Google, what is $word in German?" and it will speak it to me. This is very useful.
Then I manually add that word to my vocabulary list to study it.
I would like to write my own Python/Node microservice that will receive the word and generate flashcards (do a lookup on Linguee for sample sentences, for example) in my study program automatically.
But I would also like to keep the Google Assistant behavior that reads the translation back to me on my phone.
So is there a way to accomplish this? Basically instead of having a trigger invoke Google Assistant, I'd like it to do that and also do a second behavior (issue a POST request to a custom URL).
Thank you.

Intercept a mouse click on a hyperlink in a MS Word document in an OLE container?

I am working with Word in an OLE Container in a Delphi form, although the IDE is largely irrelevant to the question.
Up until now I have been unable to find any way of solving the above question and I have created and maintained my own word processor within my app solely because I have been unable to find a way to intercept hyperlink clicks in Word. Embedded MS Word would be the ideal solution save that Word does not expose an onHyperlinkClick event.
My embedded word processor needs to take over control of the hyperlink click as it is not navigating to a specific url, but triggers the running of a fairly elaborate function, which I cannot/do not wish to try to handle from within Word.
In the absence of an MS Word event, I would guess that the only way of doing this would be via a windows hook. I am not very familiar with hooks and would appreciate any feedback as to whether this is the best way to approach the problem. For it to work I would need the hook to be able to:
Identify the mouse coordinates on screen (that I assume is a given)
Intercept and prevent the mouse click to stop MS Word doing its own thing.
In MS Word I would need an exposed function which translates screen coordinates to the location of objects within the word document. I have looked through the Word VBA reference and couldn't find any immediately obvious function for this, but I have a feeling I have seen reference to such a function previously.
Any feedback as to whether this is a possible and sensible approach would be greatly appreciated.
I have found the answer to the above. It is fairly complex to achieve. It involves both mouse and keyboard hooks.
VBA for Word has a RangeFromPoint function which you can query to find out the the range below the mouse cursor. You then query the range object to get its hyperlinks.
You cannot query the range in the hook procedure as it causes a threads conflict. I added a timer with an interval of 1 millisecond which is enabled in the hook procedure. This makes life difficult if you want to handle the link yourself. I decided to query on mousedown rather than mousemove as latter likely to eat a lot of resource. As such you have to disable the mouse down each time and simulate it outside of the hook procedure if you want it to be handled in the normal way.
There are also all other sorts of problems to be dealt with such as other windows with a higher z order which may be lying over your ole container. You need to check if cursor falls within these windows.
You also need to make sure you don't handle the mousedown where a special key (such as shift) is depressed at the time of the mousedown otherwise you will disable selecting.
Handling opening of the link by pressing the enter key is much easier.
It would all be much easier if Word offered a hyperlinkclick event!