This is straightforward and very do-able.
1. Do not use a letterhead.doc, use a letterhead.dot, that is, a template. Calling the template (NOT opening it) makes a clone of the original. This keeps the original intact. The clone is an exact duplicate and contains all macros of the original.
2. Create a UserForm with all the fields you need - company name, address, dates etc etc. When the user clicks OK, the UserForm takes the information entered and put is into the document.
There are a number of way to do this. You could have the information go into bookmarks, or you could have them go into formfields, or you could simply have the information go in a text - although you would probably use bookmarks to locate the spots to put the text.
Here is a SIMPLE indication of what you can do. We are going to use the default names of things - just to make it easy. I strongly recommend that in the future you do NOT use default names.
1. make a new document and type:
Company:
2. Right beside Company, insert a text formfield. Use the Forms toolbar (View > Toolbar > Forms). Move your mouse around until you see it indicate a Text Formfield. Click it. A shaded rectangle appears. This is a text formfield.
3. press enter to get a new line.
4. type Address: , and then insert another text formfield.
That is all for now. Use Save As to save the file as a Word template (.dot). Call it - oh...test1.dot.
Press Alt-F11 to get the Visual Basic Editor. Press Ctrl-R to get the Project Explorer. Locate in the project tree Project (test1), and highlight it (select it).
From the menu bar select Insert > Userform. Under Project (Test1) a new item should appear "Forms". Click the little plus sign to expand it, and then double click the item UserForm1.
Select View > Toolbox so you can see the toolbox. There are a number of items on it. Move the mouse around until you find Textbox. Select it and then draw on the UserForm a box. For now it does not really matter if it is pretty. Click the textbox icon on the toolbox again, and then draw another box. Now find the Commandbutton on the toolbox. Select it and draw a button on the userform.
Press F4 - this gives the Properties window. The current control should be the commandbutton, and you may as well change the caption. In the Properties window check that the name is CommandButton1. Then change the Caption (highlight it and type in) "OK". Without the quotes - unless of course you want the quotes...
In the Project Explorer highlight the userform (UserForm1), and then press F7. This opens the code module for the form. Copy and paste the following:
Code:
Private Sub CommandButton1_Click()
If TextBox1.Text <> "" And TextBox2.Text <> "" Then
ActiveDocument.FormFields("Text1").Result = _
TextBox1.Text
ActiveDocument.FormFields("Text2").Result = _
TextBox2.Text
Unload Me
Else
If TextBox1.Text <> "" Then
MsgBox "Second textbox is blank"
Else
MsgBox "First textbox is blank"
Exit Sub
End If
End If
End Sub
Back in the Project Explorer, under Project (Test1) double click the ThisDocument item below it. Copy and paste the following into the code module that appears.
Sub Document_New()
UserForm1.Show
End Sub
Close the Visual basic Editor - use the top right Close "X".
Save the file (test1.dot).
Use the menu File > New and select test1.dot as the template. It will make a new document (a clone) and the UserForm will display immediately and will not close until you fill in both fields. The OK button will put the information into the formfields.
This is VERY VERY basic. It has minumal error trapping for the user input. Hopefully though it can show you that this kind of thing is both easy (well....relatively), but does take practice, and better yet...good design. think about how you want the form to work.
Oh, and templates MUST be called with File > New. Do not use the .dot file itself to make new files. Only open the .dot file to work on the template (master) itself.
Hope this helps.
Gerry