Does anyone know how to switch between Word documents using Jacob?
The selection Dispath object is retrieved from the Application ActiveX object using something like
ActiveXComponent m_wordApp = new ActiveXComponent("Word.Application");
Dispatch selection = m_wordApp.getProperty("Selection").toDispatch()
but this seems to take no regard of the documents open. If you want to insert some text at the current selection for Document1 there doesn't seem to be any way to guarantee it. I've found that setting a selection Range on a document works fine:
Dispatch m_allDocuments = m_wordApp.getProperty("Documents").toDispatch();
Dispatch m_document = Dispatch.call(m_allDocuments, "Open", file.getAbsolutePath()).toDispatch();
Dispatch dispRange = Dispatch.call(m_document, "Range", startIndex, endIndex).toDispatch();
Dispatch.put(selection, "Text", text);
but this means you need to know the exact position you wish to insert. I'm trying to write generic code to say "Insert this text at the current position in document1".
Any help gratefully received