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

為{幸葍}努か 提交于 2019-12-23 09:59:03

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/6536415/how-can-i-focus-on-a-word-document-i-just-opened-through-interop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!