Page 1 of 1

ActiveX or OLE for WINWORD?

Posted: Sun Mar 23, 2008 8:25 am
by Otto
I would like to start using WINWORD from FWH.
Do I have to use ActiveX or OLE?

Which libs do I have to include to use ActiveX from Harbour?


Thanks in advance
Otto

Re: ActiveX or OLE for WINWORD?

Posted: Sun Mar 23, 2008 8:46 am
by Enrico Maria Giordano
Otto wrote:I would like to start using WINWORD from FWH.
Do I have to use ActiveX or OLE?
OLE if you just want to use Word as an external application. ActiveX if you want to use Word as an embedded application.
Otto wrote:Which libs do I have to include to use ActiveX from Harbour?
Harbour? hbole.lib, I think.

EMG

Ole for Winword

Posted: Sun Mar 23, 2008 9:25 am
by ukoenig
Hello Otto,

For Winword, You can use AutoOle, same like in Excel.
I look in my archiv, to find some samples for you.

Regards

Uwe

Posted: Sun Mar 23, 2008 10:06 am
by Otto
Hello Enrico,

Thank you for your help. Now I tried the word.prg-sample from the FIVEWIN examples.
I linked HBOLE.LIB (my lib is from 2004).

But I get a Harbour exception error.

Maybe you can give me some more help.

Regards e Buona pasqua,
Otto

Code: Select all

// Using Microsoft Office Word ActiveX

#include "FiveWin.ch"

function Main()
    local oWnd, oActiveX, cString

    DEFINE WINDOW oWnd TITLE "FiveWin ActiveX Support"

    if IsActivex( "Word.Application.8" )
        cString := "Word.Application.8"
    endif
    if IsActivex( "Word.Application.9" )
        cString := "Word.Application.9"
    endif
    if IsActivex( "Word.Application.10" )
        cString := "Word.Application.10"
    endif
    if IsActivex( "Word.Application.11" )
        cString := "Word.Application.11"
    endif
    if IsActivex( "Word.Application.12" )
        cString := "Word.Application.12"
    endif

    oActiveX = TActiveX():New( oWnd, cString )

    oWnd:oClient = oActiveX                     // To fill the entire window surface

    ACTIVATE WINDOW oWnd

return nil

Posted: Sun Mar 23, 2008 12:58 pm
by Antonio Linares
Otto,

You have to link hbwin32.lib

Posted: Sun Mar 23, 2008 2:33 pm
by Otto
Antonio, thank you.
I have echo %hdir%\lib\hbwin32.lib + >> b32.bc
in my linkscript.
But the error is still there. Could you compile the file
and send me your exe for testing, please.
Maybe there is something wrong on my PC.
Thanks in advance
Otto

Posted: Sun Mar 23, 2008 4:52 pm
by Antonio Linares
Otto,

I guess you are testing Word 2007. It also GPFs here. It seems there is a conflict between Class TActiveX and Word 2007.

We are googling for some info about it, and we have found that VB users are also having troubles:

http://www.google.es/search?hl=es&q=%22 ... 2007&meta=

http://www.google.com/search?hl=en&q=%2 ... tion.12%22

Posted: Sun Mar 23, 2008 5:43 pm
by nageswaragunupudi
I am not able to use Excel 2007 also with activex. My earlier code is not working with 2007.

Posted: Sun Mar 23, 2008 6:10 pm
by Antonio Linares
Nageswararao,

What ProgID string are you using for Excel 2007 ?

Posted: Mon Mar 24, 2008 12:35 am
by xProgrammer
Hi Otto

Not sure what you want to do with Word so hard to make recommendations. If you tell us a bit more about what you want to achieve we can possibly help more.

I used Word from FiveWin code a number of times and it worked well. (I got off the Microsoft gravy train so I don't have 2007 so can't test that.)

Amongst the things I did:

FiveWin program to control word to open and convert many thousands of Word documents to straight text format so that I could do data mining on them.

FiveWin program to draft up medical reports for editing etc by doctors

FiveWin code producing reports as Word documents.

Speed was very pleasing (I didn't expect that).

For producing reports I wrote a basic class (MLETTER) to handle all the Word details in one place.

Basic code looks like:

Code: Select all

::oWord := CREATEOBJECT( "Word.Application" )
::oWord:Visible := .T.     // if you want to see it
::oDocument := oWord:Documents:Add()
::oDocument:SaveAs( sFileName, WdFormatDocument )  // WdFormatDocument is a defined constant
::oRange := ::oDocument:Range( 0, 0 )
::oRange:InsertBefore( sDateAsText )
::oRange:ParagraphFormat:Alignment := WdAlignParagraphRight   //WdAlignParagraphRight is a defined constant
::oRange:InsertParagraphAfter()
::iEnd := ::oRange:End
::oRange := ::oDocument:Range( ::iEnd, ::iEnd )
::oRange:InsertAfter( sGreeting )
::oRange:ParagraphFormat:Alignment := WdAlignParagraphLeft   //WdAlignParagraphLeft is a defined constant
::oRange:InsertParagraphAfter()
::iEnd := ::oRange:End
AS you can see the first insert is a little different (InsertAfter seems to fail with a document with no contents, but from then on its plain sailing. As you go you can add refinements, eg

Code: Select all

::oRange:Bold := .T.
::oRange:FontName := "Arial"
By the way if you just want to produce documents that Word can subsequently handle why not consider switching to the XML based standard (which Word now grudgingly supports I believe) in which case no special programming is required. I am now doing that, although I do want to write some code to control OpenOffice from a FiveLinux application (on a LInux platform)

I hope that may be of some help.

I can't guarantee that the code is 100% correct as I had to retype it and change it a bit as I went so it wasn't confused by my particular needs.

Regards
Doug
(xProgrammer)

Posted: Mon Mar 24, 2008 5:51 am
by Otto
Doug, thank you for your answer.
I only want to run the demo sample with ActiveX.

Antonio, I tried the Exe now on a WINDOWS XP/WORD2003 PC and
I get the same error:

Image

Would you be so kind to compile the above code so I can test with
your exe.

Regards,
Otto