Word automation : how to bring the document to the front ?

조회 수: 6 (최근 30일)
p fontaine
p fontaine 2012년 5월 17일
편집: Walter Roberson 2016년 9월 29일
With the following lines I can open a Word document in automation mode:
hComServer = actxserver('Word.Application');
hComServer.Visible = 1;
hComServer.Documents.Open('c:\foo.doc');
but I can't figure out how to bring the window to the front ....

채택된 답변

p fontaine
p fontaine 2012년 5월 18일
It seems that Windows prevents from such a focus stealing by default so as to defeat annoying adware ...
A solution can be to set the windows registry key
HKEY_CURRENT_USER\Control Panel\Desktop\ForegroundLockTimeout
to a decimal value of 0
then calling
hComServer.Activate
now activates and brings the window to the front but sometimes several calls seem to be necessary
(NB : reboot required after registry modification)

추가 답변 (1개)

Jan
Jan 2012년 5월 17일
Does this work:
hComServer.Visible = 1
or
hComServer.Activate
?
[EDITED]: Perhaps:
oDoc = hComServer.Documents.Open('c:\foo.doc');
oDoc.Activate;
Or:
hComServer.ActiveWindow.Activate();
You can use "methods(hComServer)" to inspect the possibilities.
  댓글 수: 2
p fontaine
p fontaine 2012년 5월 18일
unfortunately no ...
hComServer.Visible = 1 makes the Word Window visible
hComServer.Activate activates the window
but none of this commands bring the Word window to the front ......
Jan
Jan 2012년 5월 18일
Is there a command to get the hWnd of the Word Window? I do not use the Microsoft Office on my Matlab computer, because I need it for serious work, such that I cannot test this. ;-)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 ActiveX에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by