Alaska Software Inc. - filling a new word document with data from other docs and xls
Username: Password:
AuthorTopic: filling a new word document with data from other docs and xls
Hans Jeldersfilling a new word document with data from other docs and xls
on Fri, 09 Apr 2010 01:26:47 +0200
I want to create a word document and fill it with (pieces) from others word 
and excel files.

For instance the first page of the new word document has to be filled with 
data from another word document

oWord1 := CreateObject( "Word.Application" )
oDoc1 := oWord1:documents:add()
//Here I think I have to add 5 pagebreaks to create a document of 6 empty 
pages to create space
 to copy in.
//How can I do that?

//After this I have to fill oWord1 on page 1 with some fancy text (and 
images) wich are in another
 word document.

oWord2 := CreateObject( "Word.Application" )
oDoc2:= oWord2:documents:open( 'frontpage.doc' )

//I want to select the complete contents of oWord2  How do I do that?

//Then I have to copy this selection
oWord2:selection:callMethod( 'copy' )  ????

//and paste it into oWord1 on page 1
oRange1:= oDoc1:goto( wdGoToPage,, 1 ):paragraphs:last:range
oRange1:paragraphs:add()
oPara1:= oRange1:paragraphs:add()
oPara1:range:pasteSpecial( 0, .F., 0, .F., wdPaste???? )
//How do I manage when the text from oWord2 is longer than one page?

oDoc2:=nil
oWord2:quit()
oWord2:Destroy()

//Then I have to copy a table from Excel into oWord1 on page 2
oExcel := CreateObject( "Excel.Application" )
oWorkBook:= oExcel:Workbooks:Open( cPath + 'test.xls' )
oWorkBook:activeSheet:range( "A1:E2" ):select()
oExcel:selection:callMethod( 'copy' )

//and copy it on page 2 of oword1
oRange:= oDoc:goto( wdGoToPage,, 2 ):paragraphs:last:range
oRange:paragraphs:add()
oPara:= oRange:paragraphs:add()
oPara:range:pasteSpecial( 0, .F., 0, .F., wdPasteMetafilePicture )

oExcel:Quit()
oExcel:Destroy()

//etc.

Please can somebody help me to finish this?
J.A. Diego KerejetaRe: filling a new word document with data from other docs and xls
on Fri, 09 Apr 2010 06:49:38 +0200
Hans,

> For instance the first page of the new word document has to be filled with 
> data from another word document
>
> oWord1 := CreateObject( "Word.Application" )
> oDoc1 := oWord1:documents:add()
> //Here I think I have to add 5 pagebreaks to create a document of 6 empty 
> pages to create space
>  to copy in.
> //How can I do that?

#define wdPageBreak    7

oDoc:paragraphs:last:range:range:InsertBreak( wdPageBreak )

>
> //After this I have to fill oWord1 on page 1 with some fancy text (and 
> images) wich are in another
>  word document.

But this approach is wrong because it is easier to do so:

oWord := CreateObject( "Word.Application" )
   oDoc:= oWord:documents:add()

   oDoc:paragraphs:last:range:InsertFile( cMySecondDocFile, "", .F., .F., 
.F. )


Regards. Diego
Bruce AndersonRe: filling a new word document with data from other docs and xls
on Fri, 09 Apr 2010 06:44:03 -0500
Diego,
I much appreciate your wisdom.

I am printing your replys and keeping them in my binder of basic programming 
pieces to remember and copy. My clients think I am brilliant, and I don't 
mind keeping them in that misconception.

Thank you.
Bruce Anderson
Houston