Alexander - 2012-04-25

Is there any possibility to set Focus on opend WINWORD application through Jacob API?
The problem is that I open word application from Applet…and browser is still under focus.. I'd like to set focus to winword.
I tried "Activate" which just make's winword window to blink, but not set focus on it.

code snippet:

ActiveXComponent oWord = null;
        Dispatch oDocument = null;

        try {
            oWord = new ActiveXComponent("Word.Application");
            oWord.setProperty("Visible", new Variant(true));
            Dispatch oDocuments = oWord.getProperty("Documents").toDispatch();
            oDocument = Dispatch.call(oDocuments, "Open", new Variant(oldFileName)).toDispatch();
            Dispatch.call(oDocument, "Merge", new Variant(newFileName)).toDispatch();
        } catch (JacobException jacobExc) {
            AppletLogger.error(jacobExc);
        } finally {
            if (oDocument != null) {
                Dispatch.call(oDocument, "Close", new Variant(false));
            }
            if (oWord != null) {
                try {
                    oWord.invoke("Activate", new Variant);
                    AppletLogger.debug("activated");
                    Dispatch activeWindow = oWord.getProperty("ActiveWindow").toDispatch();
                    AppletLogger.debug("getting ActiveWindow: " + activeWindow.toString());
                    Dispatch.call(activeWindow, "SetFocus", new Variant).toDispatch();
                    AppletLogger.debug("setfocus");
                } catch (JacobException jacobExc) {
                    AppletLogger.error(jacobExc);
                }
            }
        }