Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I focus on a Word document I just opened through interop?

I am writing a simple Word Interop application which open a .doc file in background, changes bookmarks content, then make it visible to the user :

var App = new Microsoft.Office.Interop.Word.Application();

var ParTemplate = (object)Template;
var ParVisible = (object)false;

var Doc = App.Documents.Open(
    FileName: ref ParTemplate, // Template
    ConfirmConversions: ref missing,
    ReadOnly: ref missing,
    ...

Doc.Activate();

Doc.SetBookmarkValue("IssueNumber", TheIssue.IssueNo);
Doc.SetBookmarkValue("Title", TheIssue.Title);
...

App.Visible = true;
App.WindowState = WdWindowState.wdWindowStateNormal;

Actually, the Word application appears in the task tray, and the user has to switch to it manually.

What is the best way to make my application focus on the opened Word document ?

like image 423
Larry Avatar asked Jun 30 '11 14:06

Larry


1 Answers

Try this App.Activate(); instead of Doc.Activate().

like image 120
Bala R Avatar answered Sep 24 '22 01:09

Bala R