Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Foxpro program to trigger a "mail merge" form built in Word

Status
Not open for further replies.

PatMcLaughlin

Programmer
Dec 10, 2010
97
US
My company wants to use a program we have running that was built with Foxprow to trigger a program built with Microsoft Word or Adobe InDesign to run and send the resulting forms to a printer. We have done this often with Crystal Reports but the people who would create the reports are not familiar with the program and would like to work with the ones they have if possible. Would anyone have any input to our dilema?
 
By FoxProW, do you mean FoxPro 2.6 or Visual FoxPro? If Visual FoxPro, you can use Automation of Word.

Tamar
 
We are currently using Visual Foxpro 9 for the main process (which we call 'wilbir') Wilbir has a watched folder where all other systems will send files to be processed. When a txt file appears, Wilbir will open it and process it using the instructions coded inside. It runs 24/7 and must run without intervention of any operator. This new process would first create an xml file for use and name the report file it will be used by along with which printer/fax/email process used for the output. Our new process will then be called to run to completion and once completed, Wilbir will return for its next job. We normally use Crystal Reports but our graphics department is more comfortable with Word and InDesign.
Where would I find information about this 'Automation of Word' and in your opinion, will it handle what I have described?
 
Pat,

Just to be clear, your question is whether you can programmatically control Microsoft Word from within VFP? You want your VFP program to tell Word to create some sort of printed output, and then to go ahead and output it in some way (print it, send it via email, whatever)? Is that right?

If so, then the answer is yes. Using Automation, you can write VFP code which tells Word to do .... well, just about anything that Word is capable of doing. If Word can do what you want, then so can Automation (and without user involvement).

As for how you do that, I'm afraid you're on your own. By all means ask some specific questions about Automation, and let us know when you are in difficulty, but you will have to do the coding yourself.

You'll find plenty of information on using VFP for Automation, and also on Word Automation in general. I suggest you start with Google.

Hope this helps.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
AFAIR Mike Lewis has reported to use Word automation specifically for Mail merge.

The entry point is simple: In the command window execute oWord = CreateObject("Word.Application") and you get an instance of Word for you to automate. Intellisense will give you all options to create word documents and, yes, also to automate mail merge.

Execute oWord.visible = .t. and word will show up, but it can also stay unvisible, for a server process. You obviously need office or at least word installed, but since you want to use mailmerge and not just generate doc or docx files, I assume that already is the outset anyway.

Google vfp mailmerge and you find more pointers.
Google hentzenwerke automation and you find the hentzenwerke book on office automation with vfp. From the table of contents chapter 6 also contains info on mailmerge.

Bye, Olaf.
 
Where would I find information about this 'Automation of Word' and in your opinion, will it handle what I have described?

Start with these papers from my website:


You might also find the book Della Martin and I wrote about automating Office from VFP helpful:


Tamar
 
Pat , the #1 trick is to go into Word , click Developer . Record Macro , then do whatever you want to do with formating etc , read the macro and you can then very easily re-jig the code , that would otherwise have taken a month of sundays to figure out. You end up with a lot of with/endwith constructs, see below typical example vfp code

odoc.Sections(1).footers(1).Range.Select
With oWord.Selection
.Font.Size= 10
.Font.italic=1
Set Century On
.typetext("Created by Safety Expert on " +Transform(Date()) + " Due for review: "+cmonth(date())+ ;
+" "+transform(year(date())+1)+" "+ chr(9)+ 'Page ')
Set Century Off
.Fields.Add(.Range,33)
.typetext(' of ')
.Fields.Add(.Range,26)
Endwith


With oWord.ActiveDocument.PageSetup
.TopMargin = 100
.BottomMargin = 70
.DifferentFirstPageHeaderFooter=.T.
Endwith
 
Clipper01 - while I agree with you that recording a macro is the first step, do be aware that the macros you get tend to not be very good code. Once you start to know VBA, you can write much better code yourself than just translating a macro.

Tamar
 
Clipper,

Recording a macro is often a good plan if you are stuck for a particular bit of code. But, in this case, the questioner had clearly never even heard of Automation. What he or she needs to know is how to go about instantiating a Word object, getting an object reference to a document, and so on. Knowing how to record a macro is not going to help with that, and could add to their confusion.

(Pat: I'm sure you realise that I don't mean to denigrate your skills in this area. I just wanted to put the macro thing in perspective.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Pat , if u are using vfp9 to run 'wilbir' to process a watched folder , sounds like there is a fairly high vfp expertise there , so u should find it very easy and VERY productive to drive word from vfp, am sure we'd all be happy to post some code snippets if u run into any particular issues
 
Just to add another source of info: The solution samples comeing with foxpro also have an automation section that shows a few basics, but it doesn't go as deep as the hentzenwerke book.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top