Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
I need help quick (this weekend!) on word automation!
Message
From
25/05/2001 19:45:52
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
I need help quick (this weekend!) on word automation!
Miscellaneous
Thread ID:
00511736
Message ID:
00511736
Views:
43
I am making my first stab at word automation. I have a deadline of Tuesday AM. I am hoping to get some help over the weekend, and, if necessary, pay for consulting time, if someone can provide me with extensive help. Of course if 'quick help' will do the trick that is even better.

Here is what I am trying to accomplish:

1) My first stab at Word automation.
2) I have a word doc that has mostly fixed text. I need to replace it with some data.
(I have attachd my first cuts -prgs and docs)
3) I have studied the vb help on the word objects/methods. (I know about Della Martin's book - but it doesn't look like I could get it on short notice - unless you know of a magical way) But many things are not obvious in the docs. Any many things don't work as I expect them to.

This is my strategy so far:

1) I make a copy of a 'template doc' to another 'temp' doc.
2) I open the doc via automation.

1) Some of the data is in word tables. I think I've got the hang of replacing this data.
2) Other data is not in tables. For this data I am putting strings like 'COVER_PAGE_PRINT_DATE, in what I call the template doc. Then I am executing find/replace via the find object. If you look at the prg below - testword3.prg - there you will see what is perhaps the klugiest code of all time - don't laugh at me!

Here are some of the things that are confusing to me:
1) Since vfp does not accept named parameters, it appears that you need to list all the parameters for every method you call, as placeholders.
2) It is not obvious from the documentation what the defaults are for each method,and what will happen if you just call the method, without any parameters (e.g. odoc.close - appears to close and save by default ??/)
3) In testword3.prg the only way I could get multiple finds/replaces to happen would be to: 1) do one 2) kill the odoc object and kill word 3) recreate word application instance, etc., and do the find/replac again. When I tried to do a find/replace after doing one already, the find fails. if I set wrap to true, I get an out of range error when it executes the find.execute
4)I assume that after a find, the cursor is positioned in the doc, at the end if no find, or at the place in the doc where it found the text?? If i can't get the 'next' find to 'wrap', how can I get the cursor back to the top of the document?
5) Most of the example code given in the documentation shows setting properties of the find object, and then calling execute with only a couple of parameters. Do the parameters set in the find object control what happens in the execute? For some reason I could not get things to work right by setting properties in the find object and calling execute with no parameters.
Since vfp does not accept named parameters, it seems as if you must specify all parameters or none??, or use commas to signify position?? Most of the example code does not look like mine!

5) Are there other more efficient ways to do what I am trying to accomplish?


6) In addition to just replacing existing 'variables' with short strings, I also need to replace big chunks of text (a few pages) the pages are carefully formatted, and have gifs embedded in them. I have each 'chunk' in its own file. I want to be able to:
a) open a 'chunk' and copy it to the clipboard b) paste the chunk at the appropriate place in my document. c) repeat the process as necessary. How can I do this?

Here is the code:

#INCLUDE word2000.h


*wait wind str(wdWindowStateNormal)
oWord=CREATEobject("Word.Application")
COPY FILE execsum\execsumtemplate.doc to execsum\execsumcopy.doc


copy file testdoctemplate.doc to testdoc.doc
*lcfilename='execsum\execsumcopy.doc'
lcfilename='testdoc.doc'
oWord.Visible= .t.
oDoc=oWord.Documents.Open(lcfilename)
oDoc.activate
oRange=odoc.range

lc_find_text="COVER_PAGE_CLIENT_COMPANY"
oRange.find.ClearFormatting
lc_replacement_text="Prestige"
llretval= oRange.find.execute(lc_find_text,.f.,.f.,.f.,.f.,.f.,.t.,.f.,.f.,lc_replacement_text,.t.)
*wait wind iif(llretval,'1st execute succeeded', '1st execute failed')



odoc.close
*odoc=null
oword.quit

oWord=CREATEobject("Word.Application")

oWord.Visible= .t.
oDoc=oWord.Documents.Open(lcfilename)
oDoc.activate
oRange=odoc.range




*lc_find_text="TOP_OF_DOC"
*llretval= oRange.find.execute(lc_find_text,.f.,.f.,.f.,.f.,.f.,.t.,.f.,.f.,'',.F.)
*wait wind iif(llretval,'GO TOP succeeded', 'GO TOP failed')




lc_find_text="COVER_PAGE_PRINT_DATE"
oRange.find.ClearFormatting
lcoldcentury=set('century')
set century on
lc_mdy=mdy(date())
set century &lcoldcentury
lc_replacement_text=lc_mdy
lLretval= oRange.find.execute(lc_find_text,.f.,.f.,.f.,.f.,.f.,.t.,.f.,.f.,lc_replacement_text,.t.)
*wait wind iif(llretval,'2nd execute succeeded', '2nd execute failed')



wait wind 'Stop and wait'
odoc.close()
oword.quit()




Thanks in advance. If anyone wants to call me or email direct, please feel free.

David Schlesinger
ERP Systems Group, Inc.
1982 Washington Valley Rd | Box 309
Martinsville, NJ 08836
phone: 908.526.6665 x201
email: mailto:oaa@ix.netcom.com
web: http://www.erpsystemsgroup.com
Next
Reply
Map
View

Click here to load this message in the networking platform