How to make MS WORD on top?

How to make MS WORD on top?

Postby dutch » Thu Mar 19, 2020 11:42 am

Dear All,

I use below code to activate MS Word but it show in background. I need to activate on top of my program.

Code: Select all  Expand view  RUN
oWord := CreateObject("Word.Application")
oWord:Set("Visible",.t.)
oDoc:Open(cFile)
oWord:Set( "WindowState", 1 )  
 


How do I make on top?

Thanks in advance.
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to make MS WORD on top?

Postby Marc Vanzegbroeck » Thu Mar 19, 2020 12:41 pm

Dutch,

You can use
Code: Select all  Expand view  RUN
Setforegroundwindow(FindWindow("OpusApp",NIL))
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: How to make MS WORD on top?

Postby ukoenig » Thu Mar 19, 2020 1:54 pm

Switch from TOP to NORMAL

@ 20, 80 BTNBMP oBtn1 2007 ;
SIZE 30, 30 OF oDlg NOBORDER ;
PROMPT "Top" ;
ACTION ( SetWindowPos( oDlg:hWnd, -1, 0, 0, 0, 0, 3 ),;
WinExec( "Notepad.exe" ) )

close Notepad and reopen with button 2

@ 20, 130 BTNBMP oBtn2 2007 ;
SIZE 30, 30 OF oDlg NOBORDER ;
PROMPT "Normal" ; // Notepad on TOP
ACTION ( SetWindowPos( oDlg:hWnd, -2, 0, 0, 0, 0, 3 ),;
WinExec( "Notepad.exe" ) )

regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: How to make MS WORD on top?

Postby dutch » Thu Mar 19, 2020 3:49 pm

Thanks both of you Marc and Uwe. I try and got it work now.
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: How to make MS WORD on top?

Postby Otto » Thu Mar 19, 2020 6:19 pm

Hello Dutch,
would you be so kind to post some code.
Thank you in advance and best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6345
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to make MS WORD on top?

Postby dutch » Fri Mar 20, 2020 1:44 am

Dear Otto,

I try to use oWord:Mailmerge in my program as customer requirement for make rental contract. I got this code in the forum and modify to support in the future by create temporary file for preparing data (MergeField in Word) and can add or modify in future case.
Otto wrote:Hello Dutch,
would you be so kind to post some code.
Thank you in advance and best regards,
Otto


Code: Select all  Expand view  RUN
*---------------------------------*
Procedure DocMerge( cForm, cFile )
local oWord, oDoc, cOutFile, cTmpDbf, aTmpDbf, OkToWord , cName
local aDataField, aDatas, n

CursorWait()

cOutFile := cFile // "d:\fwh1312\samples\testdoc.doc"
cTmpDbf     := MEMVAR->cFoPath+"GSTINFO.DBF" // "d:\fwh1312\samples\guest.dbf"
cFile   := MEMVAR->cFoPath+"LTRFORM\"+cForm // "d:\fwh1312\samples\Rental.doc"

aTmpDbf     := {}
aDatas  := {}

DbUseArea(.T.,,"
EZMERGE","MRG",.T.)
do while !MRG->(eof())
    aadd( aTmpDbf, {rtrim(upper(MRG->MRG_NAME)), MRG->MRG_TYPE, MRG->MRG_LENGTH, MRG->MRG_DEC} )
    aadd( aDatas , {rtrim(upper(MRG->MRG_NAME)), rtrim(MRG->MRG_DATA)} )
    MRG->(DbSkip())
end
MRG->(DbCloseArea())

if file( cTmpDbf )
    ferase( cTmpDbf )
end
if !empty( aTmpDbf )
   
    DbCreate( cTmpDbf, aTmpDbf )
   
    sleep(1000)
   
    DbUseArea(.T.,,"
GSTINFO","GSI",.T.)
    GSI->(DbAppend())
    if GSI->(Rlock())
        for n := 1 to len(aDatas)
             &('GSI->'+aDatas[n][1]) := &(aDatas[n][2])
        next
    end
    GSI->(DbCommit())
    GSI->(DbCloseArea())
   
    oWord := CreateObject("
Word.Application")
    oWord:Set("
Visible",.f.)
    oDoc:=oWord:Get( "
Documents" )
    oWord:Set("
DisplayAlerts",0)
    oWord:Set("
Visible",.F.)
    oWord:Set( "
WindowState", 2 )  // Minimize
   
    oDoc:Open(cFile)
    oWord:ActiveDocument:MailMerge:MainDocumentType := 0 //wdFormLetters=0  // sets the mail merge main document type
    oWord:ActiveDocument:MailMerge:EditMainDocument()
    oWord:ActiveDocument:MailMerge:OpenDataSource(cTmpDbf)  //TmpDbf is the path&file name of temp database
    // oWord:ActiveDocument:MailMerge:Destination( 1 )  // 0=File, 1=Printer, 2=Email, 3=Fax
    oWord:ActiveDocument:MailMerge:Execute( .F. )
    cName:=oWord:Get("
ActiveDocument")
    //about to save check to see if possible or if someone else
    //has file open
   
   
    cName:SaveAs(cOutFile)
    IF cName:Saved() == .F.
        MsgStop("
Save to Word Fail")
        cOutFile := ''
    ENDIF        
    oWord:Documents:Close(.T.)
    oWord:Quit()
   
   
    if file(cOutFile)
        ShellExecute(0, 'Open', cOutFile,,4,0)
    end
   
end
CursorArrow()
return
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1543
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], nageswaragunupudi and 70 guests