Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Word in SWT : Application.Documents.Open fails.
Word in SWT : Application.Documents.Open fails. [message #461464] Sat, 24 September 2005 12:28
Eclipse UserFriend
Originally posted by:

I am attempting to use MS-Word OLE Control from within SWT OLE Bridge.
Initialy I would simply like to open a document programatically.
something equevelent to
Application.Documents.Open "Filename" in VBA

Basicaly the following Java code gets a reference to "Application", from
there there a reference to Documents, and than attempt to call
Open with one argument, "FileName" = "c:\1.doc"

This fails with the error:
--- The Open method or property is not available because this document
is being edited in another application.
org.eclipse.swt.SWTException: Action can not be performed. result =

I have discovered than even if I call the method with a file which does
not exist I get the same error.

help would be appriciated.

here is a snippet:

package testing.misc;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
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.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class WordSWT
private static OleClientSite _clientSite;

* @param args
public static void main(String[] args)
Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(100, 100, 500, 500);
shell.setLayout(new FillLayout());
Composite c = new Composite(shell, SWT.NONE);
c.setLayout(new GridLayout());

OleFrame frame = new OleFrame(c, SWT.NONE);
frame.setLayoutData(new GridData(GridData.FILL_BOTH));
_clientSite = new OleClientSite(frame, SWT.NONE, "Word.Document");
Button b = new Button(c, SWT.NONE);
b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
b.addSelectionListener(new SelectionAdapter()
public void widgetSelected(SelectionEvent e)


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

public static void openFile()
OleAutomation dispInterface = new OleAutomation(_clientSite);
// Get Application
int[] appId = dispInterface
.getIDsOfNames(new String[] { "Application" });
if (appId == null)
Variant pVarResult = dispInterface.getProperty(appId[0]);
if (pVarResult == null)
OleAutomation application = pVarResult.getAutomation();

int[] docsId = application.getIDsOfNames(new String[] {
"Documents" });
if (docsId == null)
pVarResult = application.getProperty(docsId[0]);
if (pVarResult == null)

OleAutomation documents = pVarResult.getAutomation();

int[] rgdispid = documents.getIDsOfNames(new String[] { "Open",
"FileName" });

Variant[] rgvarg = new Variant[] { new Variant("c:\\1.doc"), };
int nameArgs[] = new int[] { rgdispid[1] };

documents.invokeNoReply(rgdispid[0], rgvarg, nameArgs);
catch (Exception e1)
System.out.println("--- " + documents.getLastError());
Previous Topic:ApplicationWindow and Window
Next Topic:Transparent Window (SetLayeredWindowAttributes) without frame and controls
Goto Forum:

Current Time: Tue Mar 20 14:00:27 GMT 2018

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

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