Reputation:
I'm using MSWord
interop to check grammar/spell in my application. I'm using these steps to do this:
MSOffice
version independent)I'm using this code to open Word:
objWord = System.Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"));
Object objDocuments = objWord.GetType().InvokeMember("Documents", BindingFlags.GetProperty, null, objWord, null);
objDoc = objDocuments.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objDocuments, null);
objContent = objDoc.GetType().InvokeMember("Content", BindingFlags.GetProperty, null, objDoc, null);
IDataObject oldObjData = Clipboard.GetDataObject();
Clipboard.SetDataObject(text);
objContent.GetType().InvokeMember("Paste", BindingFlags.InvokeMethod, null, objContent, null);
objDoc.GetType().GetMethod("CheckGrammar").Invoke(objDoc, null);
objWord.GetType().GetProperty("Visible").SetValue(objWord, false, null);
objContent.GetType().InvokeMember("Cut", BindingFlags.InvokeMethod, null, objContent, null);
IDataObject objData = Clipboard.GetDataObject();
objDoc.GetType().GetProperty("Saved").SetValue(objDoc, true, null);
objDoc.GetType().GetMethod("Close").Invoke(objDoc, new Object[] { null, null, null });
objWord.GetType().GetMethod("Quit").Invoke(objWord, new Object[] { null, null, null });
But when I call this, only in Windows Vista, the SpellCheck window opens in the back of my application, and I need to use ALT+TAB to show the Word's window.
Anybody had this problem or have a suggestion how to solve?
I tried to call
objDoc.GetType().GetMethod("Activate").Invoke(objDoc, null);
but it doesn't work. Other "Focus" methods neither.
Thanks
Upvotes: 3
Views: 1479
Reputation: 887453
Try calling Activate
on Word's Application
object. (Not the Document
object)
EDIT: Try calling it before displaying the spell-check dialog.
Upvotes: 1