Bonjour,
Dans son message, < Brenda A. Reid > écrivait :
In this message, < Brenda A. Reid > wrote:
|| I am in the process of creating a letterhead macro/template.
||
|| I would like it to work like this: Open letterhead template, you are
asked
|| to enter a "lawyer number" and based on the lawyer number you type, that
|| lawyer's personal info is inserted in the letterhead.
||
|| An example I've been playing with is:
||
|| If txtLawyerNo = 31 Then
|| Application.Run MacroName:="ArsenaultGreg"
|| End If
||
I would suggest that you use autotexts instead (they are easy to manage and
edit). In your template, create all the autotexts you need for each lawyer
details, and, for the example I give below, call all of them
"Lawyer+LawyerNumber", as in: Lawyer1, Lawyer2, Lawyer3, etc.
Create a bookmark (named LawyerDetails for my example) where you want the
details to appear.
Finally, paste the following code in the ThisDocument module of your
template.
'_______________________________________
Private Sub Document_New()
Dim LawyerNo As String
Dim WrongNumber As Long
Dim Finished As Boolean
Dim MyAutotext As AutoTextEntry
Dim CurDoc As Document
Set CurDoc = ActiveDocument
Finished = False
With CurDoc
Do While Not Finished
'To make sure LawyerNo can be tested
'If Null value, error is generated
'So assign invalid value to start loop
LawyerNo = "A"
'Make sure user typed a number
Do While Not IsNumeric(Trim(LawyerNo))
LawyerNo = InputBox("Type lawyer number.", _
"Lawyer Details")
If Not IsNumeric(Trim(LawyerNo)) Then
MsgBox "You must type a number.", _
vbExclamation, "Number required"
End If
Loop
'Make sure number correponds to existing autotext
For Each MyAutotext In .AttachedTemplate.AutoTextEntries
If MyAutotext.Name = "Lawyer" & LawyerNo Then
Finished = True
Exit For
End If
Next MyAutotext
If Finished Then
'If autotext exists, insert it
.AttachedTemplate.AutoTextEntries("Lawyer" _
& LawyerNo).Insert Where:=.Bookmarks("LawyerDetails") _
.Range, RichText:=True
Else
'If autotext does not exist, ask user to try again or not
'OK = 1
'Cancel = 2
WrongNumber = MsgBox("The number you entered is not valid." _
& vbCrLf & vbCrLf & "Try again?", _
vbExclamation + vbOKCancel, "Invalid number")
If WrongNumber = 2 Then Exit Sub
End If
Loop
End With
End Sub
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org