Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a Word session the foreground window 1

Status
Not open for further replies.

jhall251

Programmer
Dec 7, 2000
84
US
I am sending a report to a Word doc, then opening Word and loading the doc - I want to bring the Word Window to the front from within the VFP program but dont know how - tips appreciated...

Joe Halloran
 
I don't know if you're using OLE Automation to open the Word Doc or calling ShellExecute. (I prefer the latter for just opening the doc.)

If you're using ShellExecute:
Code:
DECLARE INTEGER ShellExecute IN SHELL32.DLL ;
        INTEGER lnHWnd, ;
        STRING lcAction, ;   
        STRING lcFileName, ;
        STRING lcExeParams, ;
        STRING lcDefDir, ;
        INTEGER lnShowWindow

lnResult = ShellExecute( 0, 'open', <Filename>, &quot;&quot;, &quot;&quot;, 1 )
If you're using OLE Automation, you may not be able to do this, depending on your OS.
Code:
oWord = createobject(&quot;Word.Application&quot;)
loDocument = oWord.Documents.Open(<Word Doc file>)
oWord.Visible = .T.
oWord.Activate()
In some OSs the .Activiate() method is enough to bring Word to the front, but with XP (and maybe Win2K), it only causes the button on the TaskBar to flash, indicating the app is asking for your attention.



-BP
 
To add to what BPeisch has already said, I've written a FAQ to get around the problem of the taskbar button blinking in Win2k+ Windows OS. This FAQ will show you how to reliably bring the window to the front no matter what.

Force Window to Front (not blink in taskbar)
faq184-4262

Slighthaze = NULL
craig1442@mchsi.com
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
 
- I am using OLE Automation at the moment but I will try
SHELLEXECUTE tomorrow. Will also try oWord.Activate.

- I did find your FAQ earlier and tried using it but using oWord.Caption in the function did not seem to work - any trick to referencing a program not VFP from VFP?

Thanks as always...




Joe Halloran
 
SHELLEXECUTE() does the job - thanks.

Joe Halloran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top