Hello,
I wish to generate a new Word document (ALL.DOC) with all my customer麓s labels.
So I have a template, LABELS.DOC, and I have to add it to the Word document and next replace the fields for each Customer.
But I only get a page with the template loaded.
This is the code:
Thank you very much for your help.
Kind regards
I wish to generate a new Word document (ALL.DOC) with all my customer麓s labels.
So I have a template, LABELS.DOC, and I have to add it to the Word document and next replace the fields for each Customer.
But I only get a page with the template loaded.
This is the code:
#include "FiveWin.ch"
#include "xbrowse.ch"
#DEFINE wdCollapseEnd 0
//----------------------------------------------------------------------------//
FUNCTION MAIN()
LOCAL oWord := CREATEOBJECT( "Word.Application" )
LOCAL oSel
oWord:Documents:Open( HB_DIRBASE()+"NEWDOC.DOC" ):Select()
// First customer
oSel = oWord:Selection
oSel:InsertFile(HB_DIRBASE()+"LABEL-TEMPLATE.DOC")
WORDREPLACE( oSel, "<MyField>", "Replaced Cusomer 1" )
// Second customer
oSel:InsertFile(HB_DIRBASE()+"LABEL-TEMPLATE.DOC")
WORDREPLACE( oSel, "<MyField>", "Replaced Cusomer 2" )
// etc, I will put a do while !eof()
oWord:Visible = .T.
oWord:Documents:Close(0)
oWord:Quit()
RETURN NIL
// Those functions are from (c) Enrico .it
FUNCTION WORDREPLACE( oSel, cSrc, cRpl )
LOCAL oRng := oSel:Document:Content
IF AT( cSrc, oRng:Text ) = 0; RETURN .F.; ENDIF
oRng:Find:Execute( cSrc )
oRng:Text = cRpl
RETURN .T.
FUNCTION WORDREPLACEALL( oSel, cSrc, cRpl )
LOCAL oRng := oSel:Document:Content
IF AT( cSrc, oRng:Text ) = 0; RETURN .F.; ENDIF
WHILE oRng:Find:Execute( cSrc )
oRng:Text = cRpl
oRng:Collapse( wdCollapseEnd )
ENDDO
RETURN .T.
//----------------------------------------------------------------------------//Thank you very much for your help.
Kind regards
Muchas gracias. Many thanks.
Un saludo, Best regards,
Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]
Implementando MSVC 2010, FWH64 y ADO.
Abandonando uso xHarbour y SQLRDD.
Un saludo, Best regards,
Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]
Implementando MSVC 2010, FWH64 y ADO.
Abandonando uso xHarbour y SQLRDD.