How do I bring the Word window to front?

B

bh

I've actually done a lot of Mailmerge related driving of Word for years using
OLE, but the one nagging problem is there does not seem to be a method
equivalent to Windows' SetForegroundWindow().
Our app's users really don't want to have to click the taskbar after already
starting a merge. Is there an undocumented Application method to do this?
Or a property where I can get the window handle?
Thanks!
 
A

AA2e72E

Try (in a module):

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As
Long) As Long
Sub FL()
Dim lHandle As Long
lHandle = FindWindow("OpusApp", vbNullString)
If 0 <> lHandle Then SetForegroundWindow (lHandle)
End Sub
 
B

bh

Thanks! I was able to implement a workaround with FindWindow. The trick was
that there are multiple Word windows open at the time, so I had to first get
the window title from ActiveDocument.Name + " - Microsoft Word".
Still, it's awfully crazy to have such power with an Object, yet have to go
to such lengths for a basic operation.

Does anyone know if there's a Application, Document, or Window method that
would push it to front?

bh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top