Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » how to get word DocumentBeforeSaveEvent with ole listener?
how to get word DocumentBeforeSaveEvent with ole listener? [message #1488090] Wed, 26 November 2014 09:57
Flavio Donze is currently offline Flavio DonzeFriend
Messages: 211
Registered: July 2009
Location: Switzerland
Senior Member
I'm trying to embed word in my eclipse RCP application. Having problems to save an open editor if CTRL+S is pressed inside of the word application.

I tried the following snipped but even in this (from eclipse separated) snipped I do not get the DocumentBeforeSaveEvent event:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleControlSite;
import org.eclipse.swt.ole.win32.OleEvent;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.OleListener;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class WordMain {

    final static int DocumentBeforeSaveEvent = 0x00000008;

    public static void main(String[] args) {
        Display display = new Display();

        Shell shell = new Shell(display);
        OleFrame frame = new OleFrame(shell, SWT.NONE);
        shell.setLayout(new GridLayout());
        frame.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));

        OleControlSite site = new OleControlSite(frame, SWT.NONE, "Word.Document");
        OleAutomation doc = new OleAutomation(site);
        int[] dispInfo = doc.getIDsOfNames(new String[] { "Application" });
        Variant variant = doc.getProperty(dispInfo[0]);
        OleAutomation app = variant.getAutomation();

        OleListener listener = new OleListener() {

            public void handleEvent(OleEvent event) {
                System.out.println("DocumentBeforeSave Event, no. params:" + event.arguments.length);

        site.addEventListener(app, DocumentBeforeSaveEvent, listener);


        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {



Snippet source:

Maybe "DocumentBeforeSaveEvent" is the wrong eventId and I need some kind of key Listener, listening to CTRL+S?

What I noticed, the embeded word has it's own "save" button (top left) which is always deactivated, even if the word is modified and the should be "dirty". So maybe activating the save button (or save functionality) would then also trigger the "DocumentBeforeSaveEvent" event.

Using MS Word 2010, Java 7.


Prozessmanagement und Qualit├Ątsmanagement Software QMS/IMS
Previous Topic:Composite.print works on GC display but doesn't work on GC printer
Next Topic:StyledText
Goto Forum:

Current Time: Mon Jan 18 01:46:45 GMT 2021

Powered by FUDForum. Page generated in 0.01802 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top