Page 1 of 1
Excel window to the foreground
Posted: Thu Dec 24, 2020 11:40 am
by Natter
Hi,
Several Excel documents are open on the computer. From my program, I open Excel (CreateObject), create a new document, and want to bring it to the foreground. How can I do this ?
Re: Excel window to the foreground
Posted: Thu Dec 24, 2020 1:43 pm
by ukoenig
I use :
export xBrowse to excel
and open the result on buttonaction :
Code: Select all
@ 5, 720 BTNBMP oBBtn[17] OF oBar ;
SIZE 110, 32 PIXEL ;
BORDER ;
PROMPT " &Excel " ;
FILENAME c_Pfad1 + "Excel.Bmp" ;
ACTION ( oBrw:ToExcel(), ;
SetFocusAfter(FindWindow( "XLMAIN", 0 ) ) ) ;
FONT oFontSys ;
LEFT
[/code]regards
Uwe
Re: Excel window to the foreground
Posted: Thu Dec 24, 2020 3:25 pm
by Natter
I'm not editing a specific document, but opening a new one. So FindWindow() won't go
Re: Excel window to the foreground
Posted: Thu Dec 24, 2020 3:53 pm
by Marc Vanzegbroeck
Re: Excel window to the foreground
Posted: Thu Dec 24, 2020 4:02 pm
by alerchster
Try
Code: Select all
#include "FiveWin.ch"
function Main()
local ownd
define window ownd
activate window ownd on paint excel()
return nil
function excel()
local oExcel := CreateObject( "excel.application" )
local oBook := oExcel:Workbooks:Add()
local oSheet := oBook:Worksheets( 1 )
local hwnd
oSheet:Range( "A1" ):Value = "Last Name"
oSheet:Range( "B1" ):Value = "First Name"
oSheet:Range( "A1:B1" ):Font:Bold = .T.
oSheet:Range( "A2" ):Value = "Doe"
oSheet:Range( "B2" ):Value = "John"
oExcel:Visible = .T.
hWnd:=oExcel:hWnd
ShowWindow(hWnd, 3)
BringWindowToTop(hWnd)
return nil
Re: Excel window to the foreground
Posted: Thu Dec 24, 2020 4:51 pm
by Natter
hWnd:=oExcel:hWnd
This is what you need. Thanks !