-
Solved: Automated Forms in Word
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
-
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.
-
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.
[vba]
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
[/vba]
-
The following avoids the Selection object and preserves the bookmarks.
[vba]
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
[/vba]
-
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
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules