View Single Post
  #2   Report Post  
Posted to microsoft.public.word.pagelayout
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
Default Text Fields in Header/Footer that prompts for user input

You could obtain what you want by following the steps below.
Result: When a user creates a new document based on your template, a prompt
will pop up, asking for the title. The entered title will automatically be
inserted in the correct position and correctly formatted in the footer no
manual adjustments are needed.

What to do:

1. In the footer of your template, type Title, format the word as you wish
the title to appear in each document (Arial 8 pt, right aligned, etc.).

2. Select the Title word. Then select Insert Bookmark. Type Title in
the Name field and click OK. Now you have bookmarked this text in the footer.

3. Add a macro named AutoNew to your template (can e.g. be added to the
ThisDocument module). The macro must prompt the user for at title and update
the Title bookmark with this title. The macro below can be used.

Sub AutoNew()
Dim strTitle As String

Retry:
strTitle = InputBox("Please enter the document title " & _
"to be inserted in the footer.", "Enter Document Title")

If StrPtr(strTitle) = 0 Then
'Cancel clicked
'INSERT WHAT NEEDS TO BE DONE - CLOSE DOCUMENT?
ElseIf Len(strTitle) = 0 Then
'No title entered, let user retry
MsgBox "You must enter a title. Please retry.", vbOKOnly, "Enter
Title"
GoTo Retry
Else
'Entry OK, update "Title" bookmark
With ActiveDocument
If .Bookmarks.Exists("Title") Then
ActiveDocument.Bookmarks("Title").Range.Text = strTitle
Else
Bookmark not found
'CHANGE THE MSG AS REQUIRED
MsgBox "The title could not be inserted." & vbCr & _
"(A bookmark named 'Title' is missing in the footer)."
End If
End With
End If

End Sub


--
Regards
Lene Fredborg
DocTools Denmark
www.thedoctools.com
Document automation add-ins, macros and templates for Microsoft Word


"Ruben Torrez" wrote:

I am creating a template for a document that is often created for my company.
It will be used for each section in a larger compilation. In the template
that I am creating I have added the company name to the footer which will
exist in all documents created using this template. I also want to create a
field where the user can type the name of the section for this document.
This name will only appear in the footer, no where else in the document and
will not necessarily be the filename either (I know that a FILLIN or Autotext
can automatically add the filename or section title, but these don't seem to
work for this situation). If possible I would like this to be a formatted
field (right alignment, Arial 8pt) so that the user does not have to do this
every time they use the template. Is there a way to do this?