Bring Word to the front (ZOrder 0)

J

JSM

Hi,

I have an application which outputs RTF files to Word, which in turn runs a
macro on the open document. The problem is sometimes Word does not open in
the foreground, I need to manually select it in the task bar to bring it to
the front. How can I bring the active window in Word to the foreground
(using VBA). I've tried using the Activate method on the document's window
but it only makes it the active window in Word, it does not bring it to the
foreground. I've looked at the SetWindowPos API call but I need to pass it
the hwnd of the active window, something which to my knowledge VBA does not
provide for.

I am using Word 2000/2002 on Windows 2000.

Cheers,

John
 
L

Lars-Eric Gisslén

JSM,

Look at the WinAPI functions BringWindowToTop() and
EnumWindows()/GetWindowText()

When you call EnumWindows() you pass a pointer to your own callback function
(AddressOf YourFunc). In the callback function you call GetWindowText() with
the handle you get passed to your callback function. If the text returned by
the GetWindowText() contains 'Microsoft Word' you have the handle to Word's
application window. Use that handle with BringWindowToTop().

Regards,
Lars-Eric
 

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