| I have had several requests to provide VBA examples of how to get at merge fields in a Word document. There are several approaches but here is mine: WARNING: THIS CODE REQUIRES THAT YOU UNDERSTAND VBA PROGRAMMING AND EVENT TRAPPING. YOU MUST ALSO UNDERSTAND HOW TO USE THE NORMAL.DOT FILE. I would love to give personal instruction to everyone but just don't have the time. I guess this is my "don't try this at home" disclaimer. I have attached examples of catching the events and getting at the data source. There are two files. The first is the basic module that receives the events and the other is a class module that sets up the events. You have to declare the events object "with events" in your basic module. One note. These files are meant to be placed in the Normal.dot file so that the events are intercepted anytime Word is active. Events in Word are a little tricky that way. You have to catch the source file before it can be destroyed (by AutoWord). What I do from there is get the original Point file name and path by putting field #7 in the merge document. I then open the Point file directly so that I have all of the fields available to me (not just the ones in the merge file.) I only do this because sometimes you need to create forms that process variable data (like liabilities) and calculate the information from there. The merge file that AutoWord uses is normally placed at winpoint\work\tmpFldNameSrc.doc so you have to read that source to get the merge fields. As soon as the merge completes, this file goes away so you have to catch the document before any merge is performed. To do this, I set up the events in the Normal.dot file (Word). This is necessary to catch all load events. You can then write modules in the respective documents that catch the event and perform whatever programming you need. Alternatively, you can place the Point filename (field #7) in a bookmark. After the document merges, you can get the file name from that bookmark and open the Point file directly. You will need some method of parsing the Point file. You can use a 3rd party utility or you can write your own (instructions abound in the user forums). I use PXD17000 to read the Point file but you can parse it however you want. Once you have caught the even, you can do whatever you want. You can display a form for the user to fill out, do some calculations, reformat the document or anything else possible from VBA. This gives you a tremendous amount of power in creating "living" custom documents that become very responsive. There are other methods of achieving similar results. One very powerful (and easier-to-program) method is to use the old fashioned export in Point. All you have to export is the file name and let your program work from there. You could present a list of your own documents to print, format and customize them however you want. It doesn't have the same "feel" as printing a custom document because you can't combine Point's internal documents with that method but if you have a special application, it works very well. I hope this is helpful to someone other than me.  -Mike
- Mike mike@mtig.biz
|