Andy Trezise
2010-05-01 15:52:50 UTC
Hi All
Having fun (probably not the correct word) with Word Automation
I simply want to open a document, select the text, make changes to the text,
then write those changes out as a new page (maybe doing this repeatedly as I
skip through my database) before saving the document wih a new name.
I can get it to work by working backwards (i.e. inserting pages 'before' the
current one) but really I should be inserting pages at the end of the
document as I skip through the data in chronological order.
This is my code:
GO TOP IN "MYDATA"
oWord = CREATEOBJECT("Word.Application")
oWord.Documents.Open("c:\varcarme letterhead.dot",.f.,.t.)
oRange = oWord.ActiveDocument.Range()
cText = oWord.ActiveDocument.Range.Text
cString = CHRTRAN(cText,"%ACCOUNT%",account_number)
oWord.ActiveDocument.Range.Collapse(0)
oRange.InsertBreak(2) && This inserts a page before the currect position
oWord.ActiveDocument.Range.InsertBefore(cString)
SKIP IN "MYDATA"
cString = CHRTRAN(cText,"%ACCOUNT%",account_number)
oRange.InsertBreak(2) && This inserts a page before the currect position
oWord.ActiveDocument.Range.InsertBefore(cString)
oWord.Visible = .t.
Just wondered if anyone had done this kind of thing before.
Having fun (probably not the correct word) with Word Automation
I simply want to open a document, select the text, make changes to the text,
then write those changes out as a new page (maybe doing this repeatedly as I
skip through my database) before saving the document wih a new name.
I can get it to work by working backwards (i.e. inserting pages 'before' the
current one) but really I should be inserting pages at the end of the
document as I skip through the data in chronological order.
This is my code:
GO TOP IN "MYDATA"
oWord = CREATEOBJECT("Word.Application")
oWord.Documents.Open("c:\varcarme letterhead.dot",.f.,.t.)
oRange = oWord.ActiveDocument.Range()
cText = oWord.ActiveDocument.Range.Text
cString = CHRTRAN(cText,"%ACCOUNT%",account_number)
oWord.ActiveDocument.Range.Collapse(0)
oRange.InsertBreak(2) && This inserts a page before the currect position
oWord.ActiveDocument.Range.InsertBefore(cString)
SKIP IN "MYDATA"
cString = CHRTRAN(cText,"%ACCOUNT%",account_number)
oRange.InsertBreak(2) && This inserts a page before the currect position
oWord.ActiveDocument.Range.InsertBefore(cString)
oWord.Visible = .t.
Just wondered if anyone had done this kind of thing before.