Convert DDE to OLE

Post Reply
Jack
Posts: 249
Joined: Wed Jul 11, 2007 11:06 am

Convert DDE to OLE

Post by Jack »

Hello,
I want to convert DDE to OLE instruction when i establish link with WORD .
How to convert this ?

owrd:=Toleauto():new("word.application")
owrd:visible:=.T.
**** CONVERT the following in OLE Synthax ****
odde:=tddemlclient():new()
odde:connect("WINWORD","SYSTEM")
odde:execute('[FileOpen .Name = "MODBC.doc"]')
*
ww:=trim(com1rec->numbon1)
odde:execute('[EditReplace .Find="#NBC#",.Replace="&ww",.ReplaceAll ]')

odde:execute('[EditBookmark .Name="TETETAB",.GoTo ]')

ww:=str(com2rec->quant,3)
odde:execute('[Insert "&ww" ]')
odde:execute('[NextCell() ]')
*
odde:execute('[FilePrint ]')
ww:="c:\word\test.doc"
odde:execute('[FileSaveAs .Name ="&ww")]')
odde:execute('[AppClose ]')
odde:end()
*
Thanks for your help .
Jack
Posts: 249
Joined: Wed Jul 11, 2007 11:06 am

Re: Convert DDE to OLE

Post by Jack »

No sample about this ?

Thanks
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: Convert DDE to OLE

Post by Colin Haig »

Jack

Here is some code doing a mail merge with word - it might be of some help to you.

Enrico helped me with some of this code.

Code: Select all


static function lfMailMerge(oCode,cPath)
local oWord,oDoc,cDoc,bDoc := {|| " " },cCode := '',cName := '',cAddress := '',cAddress1 := '',cSuburb := '',lSingle := FALSE,;
      nOption := 0,aOptions := {'Print One','Print All'}


cDoc := cGetFile32('*.doc')
bDoc := {||  cDoc }

nOption := alert('Select Option',aOptions,'Printing')
if nOption == 1
   lSingle := TRUE
endif
if nOption <> 0
   do while ! oCode:eof()
      oWord := TOleAuto():New("Word.Application")
      oDoc := oWord:Documents:Open(eval(bDoc))
      oDoc:Select()
      cName     := oCode:client
      cAddress  := oCode:address
      cAddress1 := oCode:address1
      cSuburb   := oCode:suburb

      oSel = oWord:Selection
      WORDREPLACE( oSel, "#name#", ALLTRIM(cName))
      WORDREPLACE( oSel, "#address#", ALLTRIM(cAddress))
      if ! empty(cAddress1)
         WORDREPLACE( oSel, "#address1#", ALLTRIM(cAddress1))
         WORDREPLACE( oSel, "#suburb#", ALLTRIM(cSuburb))
      else
         WORDREPLACE( oSel, "#address1#", ALLTRIM(cSuburb))
         WORDREPLACE( oSel, "#suburb#", space(60))
      endif
      MsgWait('Printing Document','Please Wait',3)
      oDoc:PrintOut()
      oDoc:Close(0)
      oWord:Quit()
      oCode:skip()
      if lSingle
         exit
      endif
   enddo
   SysRefresh()
   MsgAlert('Finished Mail Merge')
endif
oCode:Top()
return(nil)
//-------------------------------------------------------------------------------------------------------------------//
STATIC FUNCTION WORDREPLACE( oSel, cSrc, cRpl )
oSel:Start = 0
oSel:End = -1

WHILE oSel:Find:Execute( cSrc )
     oSel:Range:Text = cRpl
ENDDO
RETURN NIL
//------------------------------------------------------------------------------------------------------------------//
 

Colin
Post Reply