PDA

View Full Version : Solved: Automated Forms in Word



thirstymeg
01-09-2005, 11:20 PM
Hi

I am trying to set up some automated Templates at work to enable better document control and tracking.

What i want to do is when you open a new document (using the Template) it steps you through a series of questions to fill in the bulk of the form. Currently I am just working on a basic fax document, so i just need it to prompt me for the Recipient Name, Company, Fax Number and Number of Pages. I have seen this done before so i know it can be done, just not sure how/what i have to do.

So far I have been mucking around with the ASK field but not with much success. I have set up the field via Insert / Field. When I press Okay, the prompt box then comes up straight away (which i figure is just the way it works - but if i type any info in it doesn't insert it anyway). I then assigned bookmarks to the places that i want the text to be inserted but this doesn't seem to have made much difference.

i tried saving the document both as a doc file and as a template, thinking that when i next opened it, it would prompt me for the information, but it doesn't.

Any hints/ideas you have would be wonderful, cos my head is starting to hurt - shouldn't have to do this much thinking this close to christmas!!!!

Feel free to point me in the direction of any relevent topics/forums if you know of them.

I'm starting to go NUTS!


Thanks

Megs

Jacob Hilderbrand
01-09-2005, 11:42 PM
We can do this with several Input Boxes. And have VBA drop the text to Bookmarks setup throught the document.

Can you post an attachment with bookmarks setup the way you want? I will add some code for it.

Jacob Hilderbrand
01-09-2005, 11:48 PM
Here is an example to help you get started. Make a template and add Bookmarks named Name and Address to it. Then paste the following code into the ThisDocument section of the VBE.

Option Explicit

Private Sub Document_New()

Dim Prompt As String
Dim Title As String
Dim NameInput As String
Dim AddressInput As String

Prompt = "What is your name?"
Title = "Name Input"
NameInput = InputBox(Prompt, Title)

Selection.GoTo Name:="Name"
Selection.TypeText Text:=NameInput

Prompt = "What is your address?"
Title = "Address Input"
AddressInput = InputBox(Prompt, Title)

Selection.GoTo Name:="Address"
Selection.TypeText Text:=AddressInput

End Sub

Howard Kaikow
01-10-2005, 04:26 PM
The following avoids the Selection object and preserves the bookmarks.


Option Explicit

Private Sub Document_New()
Dim Prompt As String
Dim Title As String
Dim NameInput As String
Dim AddressInput As String

Dim rngCurrent As Word.Range

Prompt = "What is your name?"
Title = "Name Input"
NameInput = InputBox(Prompt, Title)

Prompt = "What is your address?"
Title = "Address Input"
AddressInput = InputBox(Prompt, Title)

With ActiveDocument
Set rngCurrent = .Bookmarks("Address").Range
rngCurrent.Text = AddressInput
.Bookmarks.Add Name:="Address", Range:=rngCurrent

Set rngCurrent = .Bookmarks("Name").Range
rngCurrent.Text = NameInput
.Bookmarks.Add Name:="Name", Range:=rngCurrent
End With
End Sub

mdmackillop
01-10-2005, 04:34 PM
There's a userform sample here which shows how you can enter recurring data stored in an excel spreadsheet, within the userform, or manual entry as required.
http://www.vbaexpress.com/kb/getarticle.php?kb_id=184