[Tutor] Activate window

Scott Widney SWidney@ci.las-vegas.nv.us
Wed Oct 23 15:54:01 2002


> > However I actually thought the original poster was asking
> > how to do it from Python! I think the win32 module and
> > visible=1 posted earlier were the correct answers...
> 
> I believe that using the visible property of Excel and Word through
> win32com will determine whether or not the window is shown or hidden,
> but it won't activate the window (make it the foreground window and
> give it the focus).  It may be necessary to use Windows Scripting Host
> features for that (which are also available through win32com).  Excel
> and Word may also have a method to activate themselves, so try
> searching through their scripting docs for "Activate".

For the impatient:

>>> import win32com.client
>>> xl = win32com.client.Dispatch("Excel.Application")
>>> xl.Visible = 1
>>> wd = win32com.client.Dispatch("Word.Application")
>>> wd.Visible = 1
>>> sh = win32com.client.Dispatch("WScript.Shell")
>>> sh.AppActivate(wd)
1
>>> sh.AppActivate(xl)
1
>>>


Enjoy!
Scott