Jump to content
Sign in to follow this  
sigil

Document opened with WordCreate() doesn't take focus

Recommended Posts

sigil

The following code should open a Word document selected by the user, and that document should end up being the active window.

#include <word.au3>

$path=fileopendialog("Choose File",@desktopdir,"Word Documents (*.doc)")
$wObj=_wordcreate($path)
$wWin=wingethandle($wObj)
winactivate($wWin)
winwaitactive($wWin)

What actually happens is this: the document opens and is the foremost window, but it is grey on the top, i.e., not active. What can I do to make the document end up being active?

Share this post


Link to post
Share on other sites
MikeP

#include <word.au3>
Opt("WinTitleMatchMode", 2)
$path=fileopendialog("Choose File",@desktopdir,"Word Documents (*.doc)")
$wObj=_wordcreate($path)
$wWin=wingethandle($wObj)
winactivate("Word")
winwaitactive("Word")

quick answer.. maybe not the best since i'm using string file name and you're using handles which isn't pretty..but at least it does what you want

Edited by MikeP

Share this post


Link to post
Share on other sites
sigil

:BUMP:

I still haven't been able to get this to work. MikeP, I can't use your solution because it doesn't work properly if I have another window with the word "Word" in its title.

I'm getting a confusing result when I test the data in $wObj. With this code:

#include <word.au3>

$path=fileopendialog("Choose File",@desktopdir,"Word Documents (*.doc)")
$wObj=_wordcreate($path)
$wWin=WinGetTitle($wObj)
msgbox(0,"",$wWin)
winactivate($wWin)
winwaitactive($wWin)

the MsgBox() shows the path for the script that I'm running, not the Word doc that I chose with FileOpenDialog().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×