Author: Dean Brown (with help
from various sites & newsgroups on the net, of course!)
Language: VB5enterprise, SP3
Requirements: O'Reilly's WebSite Server, Word 97, WinNT/9x
Purpose: Allows web users to customize a Word document for downloading.
Features: Allows unlimited replacement fields in the Word Doc, multiple
replacements, each user gets their own doc (that they name).
|NTS3.51 (SP5), WebSite v1.1h, Word 97 (SR-1), VB5ent (SP3)
||NTW4 (SP4), Netscape4.61, IE5
Download the Exe:
Try it out:
Place cgimodifyworddoc.exe in your cgi-win dir (You can rename this file
if you want - keep the ".exe" though!). Make sure you have the VB5 runtime
files and Word97 installed on the webserver.
Create a Word97 Doc (which will act as a template) that has fields in it
that you wish to replace: #username#, #address1#, #phonenum#, etc (download
an example Word Doc template). Save this file in
the same dir as the exe in step 1.
Create an "ini" text file that holds the following info:
Save this file in the same dir as the exe
in step 1. Name it the same as your Word doc (for simplicity sake). (download
an example ini file).
- Number of unique field names,
- the name of the template doc (from step 2),
- the name of your domain and the path (dir's) where the new doc will be (in URL format)
- the full path of where to save the new doc (make sure that this path actually exists!) (DOS format),
- the start and end characters that identify the fields (the #'s from above)
- and a list of the field names.
Create a webpage with a form that asks the user for the info to replace
the fields in the Word template as well as the name of the new doc that
they will download (check the source of this page for an example). Point
the form's action parameter to the exe file in step 1. Make sure that the
name of the fields in the webpage form match the ones in the ini and Word
template file. There is a hidden input in the form as well - it holds the
name of the ini file.
What the program does:
It first gets the name of the ini file and name of the document to be saved
from the form. (It cleans up the new name so that it only contains letters
It then inputs the number of fields, name of the template doc, the save
directory, and the start and end field characters.
It then loads the name of the fields from the ini file and gets the users
inputed data fro the webpage form.
The program then starts the Word Application on the server (it doesn't
show since it called by the system), opens the file named in the ini file,
replaces all the fields with the users data, saves the doc as a new doc
in the SaveDir, as stated in the ini file, closes the doc and exits Word.
The last step sends a message back to the user as a web page, which links
directly to the new Word Doc.
There is very simple error handling (so far), so follow the structure of
the ini file, webpage form and Word Doc exactly. I'll be adding more descriptive
error handling later (if there is demand).
Use the program with caution! I haven't tested it out on all systems under
all circumstances so I'll have to say use at your own risk! I'm not responsible
for anything that happens to your computers due to the use of this program.
The program is free for all to use. I'll I ask is that if you find it helpful,
let me know (by email), and please send me a postcard from your fair city.
My address is Dean Brown, 143 Poyntz Ave, Toronto, ON, M2N 1J3, Canada.
If you have any suggestions on how to make this program better (I have
lots lined up already). I can make the source code available to those who
wish it as well.