B
Brenda A. Reid
Help please. The following is part of my letterhead template. I have
autotext entries to select the lawyer for the letterhead. I now have some
lawyers with 4 numbers. 4 numbers will not work but any with 3 numbers
will. Can anyone tell me why an autotext entry like Lawyer8888 will not
work but Lawyer888 will?
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
autotext entries to select the lawyer for the letterhead. I now have some
lawyers with 4 numbers. 4 numbers will not work but any with 3 numbers
will. Can anyone tell me why an autotext entry like Lawyer8888 will not
work but Lawyer888 will?
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