Problem with OLE and Microsoft Word

Problem with OLE and Microsoft Word

Postby driessen » Fri Apr 07, 2023 12:44 pm

Hello,

I did this test:
Code: Select all  Expand view
oWord := TOleAuto():New("Word.Application")
oWord:Quit()
oWord:= NIL

oWord := TOleAuto():New("Word.Application")
oWord:Quit()
oWord:= NIL

oWord := TOleAuto():New("Word.Application")
oWord:Quit()
oWord:= NIL

I wanted to test the speed by which Word is opened and closed by using OLE.

After the Quit-command, it lasts at least 10 to 15 seconds before Word is effectivily closed.

What can be down to make this process much quicker?

Thank you very much for any advice.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Problem with OLE and Microsoft Word

Postby Natter » Fri Apr 07, 2023 1:37 pm

You can find the process in Word memory (via WMI) as "OpusApp" and delete it
oProcess:Terminate()
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Problem with OLE and Microsoft Word

Postby driessen » Fri Apr 07, 2023 2:58 pm

Sorry, I don't have any experience with this. Can you please provide me with an example? Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Problem with OLE and Microsoft Word

Postby Natter » Fri Apr 07, 2023 4:59 pm

Something like this
Code: Select all  Expand view
procedure KillProcess()
local st
local oWmi:=WmiService(), oList, oProc
private dim:={"WINWORD.EXE", "OpusApp", {}}

  EnumChildWindows( 0, ;
      { | hCt, nLParam | L_Tsk(hCt) }, 0 ) // optional supplied value

  for st=1 to len(dim)
    oList:= oWmi:ExecQuery( "select * from Win32_Process where Name = '" + ;
                                                          dim[st,1] + "'" )

    for each oProc in oList // list of processes
        oProc:Terminate()
    next
  next
return nil

Function L_Tsk(hWn) && CALLBACK of EnumChildWindows
local fl
** hWn - handle of window 

    fl:=ascan(dim, {|xx|xx[2]=GetClassName(hWn)})
    if fl>0 // this is the desired process 
      aadd(dim[fl,3], {GetWindowProcessID(hWn), hWn})
    endif
return .T.
 
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: Problem with OLE and Microsoft Word

Postby karinha » Fri Apr 07, 2023 5:52 pm

Code: Select all  Expand view

#include "FiveWin.ch"

static oWnd

function Main()

   local oBar, cPdf

   //cPdf := "C:\FWH\SAMPLES\MODELO.PDF"       // NO FUNCIONA
   //cPdf := "C:\FWH\SAMPLES\MATERIAL.TXT"  // FUNCIONA, IMPRIME NORMAL.
   //cPdf := "C:\FWH1905\SAMPLES\MODELO.RTF"   // FUNCIONA, IMPRIME NORMAL.
   cPdf := "C:\FWH1905\SAMPLES\DATA_DOC.doc" // FUNCIONA, IMPRIME NORMAL.

   DEFINE WINDOW oWnd TITLE "Test Word"

   DEFINE BUTTONBAR oBar _3D OF oWnd

   DEFINE BUTTON OF oBar ACTION( PrintPDF( cPdf ) )

   SET MESSAGE OF oWnd TO "Test Word" NOINSET CLOCK DATE KEYBOARD

   ACTIVATE WINDOW oWnd

return nil

function PrintPDF( cPdf )

   local oWord, oDoc, lVisible

   if Empty( cPdf ) .or. !File( cPdf )

      MsgAlert( "Invalid File Name" )

      return .f.

   elseif ( oWord := WinWordObj() ) == nil

      MsgAlert( FWString( "Word not installed" ) )

      return .f.

   endif

   oWord:DisplayAlerts := .f.

   lVisible := oWord:Visible

   // oWord:Visible := .f.

   oDoc := oWord:Documents:Open( truename( cPdf ), .f., .t. )

   // oDoc:PrintOut()  // Se que quiser direto na impressora de PDF.
   // oDoc:Close()

   // oWord:Visible := lVisible
   oWord:Visible = .T.
   oWord:WindowState = 1 // Maximize

   SETFOREGROUNDWINDOW( FINDWINDOW( "OpusApp" ) )

return .t.

// FIN
 


Code: Select all  Expand view

// http://forums.fivetechsupport.com/viewt ... ff84ac719d

#include "Fivewin.ch"

FUNCTION MAIN()

   LOCAL cDoc := CURDRIVE() + ":\" + CURDIR() + "\test.doc"
   LOCAL oWord

   If FILE( cDoc )

      oWord = TOleAuto():New( "
Word.Application" )
      oWord:Documents:Open( cDoc )
      oWord:Visible = .T.
      oWord:WindowState = 1 // Maximize

      SETFOREGROUNDWINDOW( FINDWINDOW( "
OpusApp" ) )

   ENDIF

RETURN NIL


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Problem with OLE and Microsoft Word

Postby driessen » Fri Apr 07, 2023 6:27 pm

Guy,s

Thank you so much for your help.

I know what to do this weekend. Testing, testing, testing.

Happy Eastern to you all.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Problem with OLE and Microsoft Word

Postby Natter » Fri Apr 07, 2023 6:54 pm

Maybe, I didn't check, you can try

oWrd:=GetActiveObject(...
....................
SendMessage(oWrd:hWnd, VM_CLOSE)
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 61 guests