Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Macro to be called from VFP
Message
 
 
To
28/08/2000 07:58:57
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00409726
Message ID:
00409741
Views:
18
Peter,

Sounds like you need to do some Automation work! It's not hard. The easiest way to get the basis for the code you want is to go to Word and open a new document. Turn on the macro recorder, and interactively perform all the searches/replaces and so forth. (Keep it to a reasonable number of steps, say, open the file, and do one or two search/replaces -- you can always run the macro recorder again to collect the formatting steps, and again to do something else.) When finished, turn off the macro recorder, then edit the macro. Now you have VBA code. And it looks *sorta* similar to VFP code, with some notable exceptions. Copy this code to the clipboard.

Now go into VFP. Open a new program (or method), and paste it in. At the top, you'll want to give the following lines:

oWord = CreateObject("Word.Application")
oWord.Visible = .T.
WITH oWord

Then you'll convert all the code into VFP. Generally you'll put a period in front of the properties/methods (you're in the WITH), and remove the named parameters (the "Name:=" part -- just delete it, and hope it wrote the parameters out in the right order.) Add the last ENDWITH line, and you're ready to run (and start debugging the errors...oops, I mean "fine tuning" <vbg>).

There are plenty of online docs here at the UT for help on Automation. Also try searching the MSDN KB for "foxpro word automation" -- it nets *some* stuff (though the stuff here is probably better!). And finally, the "best" source (if I do say so myself) is the book Tamar Granor and I wrote called "Automating Microsoft Office from Visual FoxPro" available at www.hentzenwerke.com -- it covers all this and has some good examples to show text and formatting Search and Replace.

Once you get started, post some more specific questions, and I think we can help you.

Hope this helps!

- della Martin

>I create a word document from within VFP for local printing. The straight text will be sent to a AS400 for publishing and the pagination on that machine is as asenine as it can get.
>Anyway there are not formfeed anywhere.
>
>No in order to print it also locally I desided to send the text to MSWord.
>Now I need to do the following:
>
>Find the all instances of the word PAGE:, go to the beginning ofthe line, insert a pagebreak and also make the line Bold and Underlined.
>
>(there are apprximately 500 pages)
>
>
>And as another challange I need to overlay a form over the text. Like preprinted text, lines between columns and lines every fourth row and the like.
>
>Any ideas anybody ??
>
>Thanks
>
>Peter
>
>PS. I don't know VBA at all. There seems to no do while not eof() equivalent.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform