1
votes

I have a shell script that takes one text argument and returns an image from that. I want to add this to word ribbon bar as a button and replace the selected text with the image produced by the script (basically copy-paste). What is the best way to do it?

  1. create c# word add-in and manually add it to add-in ribbon
  2. create vba add-in and create word.ribbonui xml
  3. create macro and ...
  4. use windows com as passing messages and create client-server system
  5. use activeX
  6. something else
  7. some different combination of the above

Also, if you have some tutorial or pseudocode how to do it in practice it would be helpful. I am not looking a complete answer just some tips where should I start.

The script is python and word is 2010. Additional bonus is, if it is possible to package for distribution (some GPL style license).

EDIT:

Some things that I have learned...

  • ActiveX belongs to COM (component object model) group
  • you need visual studio 2010 pro in order to have c#/vba office developement tools
  • there exists "excelAddin.py" google that uses win32com, and works after a few tweaks
  • there exists a win32con.WM_GETTEXT and WM_GETSEL messages: see How to retrieve the selected text from the active window

Next: put all together, and write the answer...

related stuff:

1

1 Answers

1
votes

Here's the outline:

  1. create com-service
  2. register com-service (only for the first time)
  3. add manually com-service to ribbon bar

Step 1 - creating the com service:

class myService:
   def mandatoryInitFunction1(self,arg1,arg2,arg3): 

   def mandatoryKillFunction1(self,arg1,arg2,arg3): 

   def mandatoryXFunction1(self,arg1,arg2,arg3): 

   def mandatoryCallbackFunction(self,arg1,arg2,arg3):     
       selection = wincom.WM_GETTEXT(argX)
       popen(selection, shell=True)

step 2 - registering the service:

  • see excelAddin.py

step 3 - adding to ribbonbar:

  • word -> options/preferences -> ribbon -> com-objects -> myService