FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour [Tip]: Setting focus to Excel
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

[Tip]: Setting focus to Excel

Posted: Thu Apr 16, 2009 08:03 AM
I don't know how technically accurate or efficient this is but it's what I've tried and so far worked for me.

Here's the scenario.
Code (fw): Select all Collapse
 .
 .
   oExcel:ActiveWorkBook:SaveAs(cFullPath)
   oExcel:DisplayAlerts := .t.
   msginfo("Data has been saved at"+CRLF+cFullPath)
   SetFocusAfter(FindWindow( "XLMAIN", 0 ))
   oExcel:visible := .t.
 .
 .


Based on snippet above, you can see after exporting some data into an Excel file, I wished to inform the user the full path of where it was saved. After that was done I'd like to bring Excel into focus. After trying a couple of ways, SetFocusAfter() works as I need it to and this is how it was coded:
Code (fw): Select all Collapse
function SetFocusAfter(hWnd)
  local oTimer

 define timer oTimer interval 500 of oWnd    ;
   action (BringWindowToTop(hWnd), oTimer:DeActivate())

 activate timer oTimer
return Nil
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion