h = actxserver('WScript.Shell');
h.Run('notepad'); %Invokes notepad.exe
pause(3); %Waits for the application to load.
h.AppActivate('Notepad'); %Brings notepad to focus
h.SendKeys('hello world~'); %Sends keystrokes
h.SendKeys('^s'); % save file
pause(3);
h.SendKeys('test.txt~'); % save as 'test.txt' and return
h.SendKeys('%{F4}'); % close Notepad Alt+F4
The above example illustrates that you can send keystrok
The above code allows me to open an external application like notepad. However, I want to try the above code with microsoft word or adobe. How can I implement those changes?
thanks

 채택된 답변

AA
AA 2015년 1월 22일

1 개 추천

h = actxserver('WScript.Shell');
pause(3); %Waits for the application to load.
h.AppActivate('Notepad'); %Brings notepad to focus
The above code gets notepad into focus and then I can send hotkeys and other commands to it.
How can I get microsoft word or excel into focus in order to the same thing to it?

추가 답변 (1개)

Zoltán Csáti
Zoltán Csáti 2015년 1월 22일

3 개 추천

If you want to open an external file outside MATLAB, use the exclamation mark operator. In your case:
!notepad.exe
All you have to do is search on the internet how to open those applications from the command line.

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

질문:

AA
2015년 1월 21일

댓글:

2021년 7월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by