Question Locked

Microsoft Word "Template"

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I had a coworker ask me today if I knew how to make a template in Word. I said yes and he proceeded to tell me what he wanted it to do. Turns out he wants to have a template that will allow you to fill in a blank with the touch of a button (F9 or something). He wants it to open another box so you can enter more text and prompt you for what is supposed to go there (ie. if it is looking for your name, you hit F9 and a box pops up saying something like "Enter Your Name Here"). I've been doing some searching on 'Word Templates' but can't find anything regarding the box popping up. Any help would be greatly appreciated.

Bob

5 replies

by thumbsup2

Popup boxes asking you questions and filling the answer into a form field can be accomplished with use of a macro. Have you started to learn Visual Basic yet?

by turland1

I guess i will have to go back into my old text books and relearn that. I will have to speak with my coworker and find out if it is worth the time it will take to relearn it. Thanks.

by nimmo

If you want functionality like that you will need to script it in vbs.

by computercookie

then create the macro, forget about using "hotkeys" such as F9.

Sample of a Memo template below minus formatting and embedded logos;

GoldPlate Motors

Inter Office Memo

To:

From: Jeff

Date: 20/02/2008

Subject:

The macro is one I wrote three years ago as part of an assessment, the profuse use of REM statements is to prove I understood the code. A mate of mine said it was "overblown and he could have written a shorter script, and I'm sure there are many members here who could write a better one.

You will need to create you own autorun.exe file. The macro is designed to run a dialog box that requires the addressee, date and you should not be able to save the file unless you have a this data.

The dialog boxes pop up and ask for the information and once you click on ok it will move the cursor to the next location on the template and another dialog box will pop up until your reach the point where you enter the text of the memo.

If you cut and paste the Memo Template into a word document and save it as a template, then go to tools and open the visual basic editor and copy the macro into there, save and reopen the template, select the macro and run. If you want the macro to start automatically you will need to in create your own autorun.exe to include.

Sub GoldPlateMotors1()
' GoldPlateMotors1 Macro
' Macro recorded 18/10/2005 by Jeff Cook
Rem Ask for Recipients Name,if empty string calls error check funcion and requests close or restart
'Declare variables
Dim inpstring As String

inpstring = InputBox("Please enter the Recipients Name", "Recipients Name") 'Requests name
If (inpstring = "") Then 'Function "If" and empty string calls Function "Check_for_Close_or_Restart"
Call Check_for_Close_or_Restart 'Calls Function
Else
GoldPlateMotors2 (inpstring) 'Goes to Subroutine GoldPlateMotors2 if string <>"" and passes declared variable in
End If 'inpstring Subroutine GoldPlateMotors2 this negates the having to declare inpstring
'as a varible in Subroutine GoldPlateMotors2
End Sub
Sub GoldPlateMotors2(inpstring As String) 'Imports Variable inpstring
'Executes if inpstring <>"" or Function "Check_for_Close_or_Restart" initiates

Selection.GoTo What:=wdGoToBookmark, Name:="To" 'Gets Bookmark
Selection.Text = inpstring 'Inserts text typed into Input Box
Selection.GoTo What:=wdGoToBookmark, Name:="Date" 'Gets Bookmark
inpstring = InputBox("Please enter the Date", "Date", Date) ' Input Box requests Date
Selection.Text = inpstring 'Inserts current date by "OK" or allows dare to be altered(not recommended)
Selection.GoTo What:=wdGoToBookmark, Name:="Subject" 'Gets Bookmark
inpstring = InputBox("Please enter the Subject", "Subject") '
Selection.Text = inpstring 'Inserts text typed into Input Box
Selection.GoTo What:=wdGoToBookmark, Name:="Body" 'Gets Bookmark
Selection.Text = "" 'Allows text to be inserted into the body of the Memo

With ActiveDocument.Bookmarks 'Describes bookmarks in the active document as being sorted
.DefaultSorting = wdSortByLocation 'by "Location" rather than "Name" and hidden bookmarks can
.ShowHidden = False 'be displayed
End With
End Sub
Public Function Check_for_Close_or_Restart() As Integer 'Function called by "If" Function in GoldPlateMotors1 when
'instring = ""
'Function requires value when a Function is called from
'within, the MsgBox and InputBox are Functions
'hence declared variables are the value
'Declare variables

Dim inpstring As String
Dim response As Integer

response = MsgBox("Do you wish to Close this Program", vbYesNo, "Close") 'Function Error check

If response = vbYes Then 'If val = 6,vbYes Close
ActiveDocument.Close
Application.Quit '
Else 'Else val = 7,vbNo
response = MsgBox("This will restart the macro!", vbOKOnly, "Restart") '"OK" to restart the macro
inpstring = InputBox("Please enter the Recipients Name", "Recipients Name") 'If val =1, vbOKOnly,restarts macro
GoldPlateMotors2 (inpstring)
End If

End Function

This discussion is closed to new replies.